Author Topic: Template conditions  (Read 6077 times)

Offline alancio

  • Newbie
  • *
  • Posts: 2
Template conditions
« on: May 09, 2008, 12:23:47 PM »
How does one uses conditions in Roundcube's templates?

I tried this in taskbar.html:





And it always shows the button, even if $_SESSION['admin'] evaluates to false.

I tested with:
$_SESSION=false;
$_SESSION=0;
(and by not setting $_SESSION['admin'] at all)

Thanks.

Offline rosali

  • Hero Member
  • *****
  • Posts: 2,533
Template conditions
« Reply #1 on: May 09, 2008, 03:13:19 PM »
Since 0.1.0 stable $_SESSION is managed by $USER object. This means you have to store $_SESSION['admin'] in the user properties (Database !) before you can use it...

$a_prefs = $USER->get_prefs();
$a_prefs = .... your modifications
$USER->save_prefs($a_user);
unset($USER);
$USER = new rcube_user($_SESSION['user_id']);

... now you modifications are present in the $CONFIG and you can use ...

config:admin

SECURITY ... SECURITY

-Roland
Regards,
Rosali
__________________
MyRoundcube Project (commercial)

Offline wildnove

  • Newbie
  • *
  • Posts: 1
Problem working with template language under taskbar.html
« Reply #2 on: March 10, 2009, 04:46:20 AM »
I have modifyed taskbar.html in this way (and also main.inc.php adding config var flag_admin).

Code: [Select]
<div id=&quot;taskbar&quot;>
<roundcube:button command=&quot;mail&quot; label=&quot;mail&quot; class=&quot;button-mail&quot; />
<roundcube:button command=&quot;addressbook&quot; label=&quot;addressbook&quot; class=&quot;button-addressbook&quot; />
<roundcube:button command=&quot;settings&quot; label=&quot;settings&quot; class=&quot;button-settings&quot; />
<roundcube:button command=&quot;logout&quot; label=&quot;logout&quot; class=&quot;button-logout&quot; />

<roundcube:if condition=&quot;config:flag_admin == true&quot; />
<roundcube:button command=&quot;admin&quot; label=&quot;admin&quot; class=&quot;button-admin&quot; />
<roundcube:endif />

</div>

Condition in var_dump debugging is working (switching config var true or false), but
the content of if condition is always displayed (not switch).
Someone is able to do this? :eek:


My debugging is based on rcube_template.php modifying

Code: [Select]
   private function xml_command($command, $str_attrib, $add_attrib = array())
    {
        $command = strtolower($command);
       
        $attrib  = parse_attrib_string($str_attrib) + $add_attrib;

        var_dump($attrib);
        echo 'command: '.$command."\n";
        echo 'check: '.$this->check_condition($attrib['condition'])."\n\n";
        // empty output if required condition is not met
        if (!empty($attrib['condition']) && !$this->check_condition($attrib['condition'])) {
            echo "\nRitorna vuoto!!\n";
            return '';
        }

so I can see that condition is working (eg false) but in the next call to xml_command

Code: [Select]

is still visible.

Why?
« Last Edit: March 10, 2009, 04:49:59 AM by wildnove »