Robin Elfrink wrote:

> I have a first rough implementation of conditional objects in templates.
> 
> An object in a template file can have an extra attribute called
> 'conditional', which holds a condition like 'varname==value'. '==' can
> be '!=', or '<=' or any other expression. 'varname' is any $CONFIG variable.
> 
> In the example the messagelist is only shown if the mailbox-name is 'INBOX'.

Didn't test enough, and found out that mailbox is not a config var. Duh.

Now if I add:
$rcmail_config['xx'] = 'yy';

the attached patch works.


> Am I going in the right direction?


Robin
Index: program/include/main.inc
===================================================================
--- program/include/main.inc    (revision 369)
+++ program/include/main.inc    (working copy)
@@ -1225,7 +1225,18 @@
       
       // execute object handler function
       if ($object_handlers[$object] && 
function_exists($object_handlers[$object]))
-        return call_user_func($object_handlers[$object], $attrib);
+        {
+        if (isset($attrib['conditional']) &&
+            preg_match('/^([a-z0-9_]+)([=<>!]+)([a-zA-Z0-9_]+)$/', 
$attrib['conditional'], $condition))
+          {
+            if (eval("return \$CONFIG['" . $condition[1] . "']" . 
$condition[2] . "'" . $condition[3] . "';"))
+              return call_user_func($object_handlers[$object], $attrib);
+            else
+              return '';
+          }
+        else
+          return call_user_func($object_handlers[$object], $attrib);
+        }
         
       else if ($object=='productname')
         {
Index: skins/default/templates/mail.html
===================================================================
--- skins/default/templates/mail.html   (revision 369)
+++ skins/default/templates/mail.html   (working copy)
@@ -45,6 +45,7 @@
   id="messagelist"
   cellspacing="0"
   summary="Message list"
+  conditional="xx==yy"
   messageIcon="/images/icons/dot.png"
   unreadIcon="/images/icons/unread.png"
   deletedIcon="/images/icons/deleted.png"

Reply via email to