Page 1 of 1

Can Smarty be used in a User Defined Tag (UDT) (SOLVED!)

Posted: Fri May 16, 2008 6:29 pm
by jmcgin51
Can Smarty be included in a UDT?  When I try to include Smarty in a UDT, I get the following error:

    * Invalid code entered.
    * Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in
\\mypath\adduserplugin.php(94) : eval()'d code on line 1

I found this in the documentation: http://wiki.cmsmadesimple.org/index.php ... _.28UDT.29

but I don't understand how to implement it, or if it can be used in my situation.

Here's my situation.  I have a site where I'm using FEU and CC to provide different content to different users.  I'm also using the excludeprefix and includeprefix parameters for my menus so that the nav menu also shows different tabs for different users.  Everything works fine, but I currently have to include all my menu logic in EACH page template, like this:

{menu template='simple_navigation.tpl' collapse='1'}
{elseif $customcontent_memberof_group1 > 0}
  {menu template='simple_navigation.tpl' collapse='1' excludeprefix="group2_"}
{elseif $customcontent_memberof_group2 > 0}
  {menu template='simple_navigation.tpl' collapse='1' excludeprefix="group1_"}
{else}
  {menu template='simple_navigation.tpl' collapse='1' excludeprefix="group1_,group2"}
{/if}

Since I have several templates, this means quite a bit of editing any time I need to change this logic (new groups, etc.)

I'd like to create a UDT with the menu logic, and just call that UDT at the appropriate place in my template.  Then, if I need to change groups or logic, I just edit one UDT instead of multiple templates.

How can this be done?

Re: Can Smarty be used in a User Defined Tag (UDT)

Posted: Fri May 16, 2008 7:03 pm
by calguy1000
copy the logic into a Global content block
and then just insert the global content block into each of your templates.

UDT's are PHP code, GCB's are smarty.

Re: Can Smarty be used in a User Defined Tag (UDT)

Posted: Fri May 16, 2008 7:26 pm
by jmcgin51
thank you!  If I get a chance, I'll add that to the Wiki.  I looked all over the forum and documentation, and didn't really see it stated as clearly as you just did.

off to create a GCB... :-)