Forums / Developer / conditional include in template language

conditional include in template language

Author Message

Pascal Specht

Monday 09 February 2009 8:30:07 am

Hi there,

I want to have the same frontpage showing different html tables depending if the user is anonymous or member: I tried to introduce a new CustomTag like in the code below, thinking that this would work, but obviously, the template engine properly complains about the malformed syntax and it doesn't work.

My XML block looks like this:

<custom name="startif"></custom>
...should only appear if the isMember() function is true...
...other html code here
...
<custom name="endif"></custom>

templates/content/datatype/view/ezxmltags/<b>startif.tpl</b>:

{if isMember()}

templates/content/datatype/view/ezxmltags/<b>endif.tpl</b>:

{/if}

Any other ideas or help greatly appreciated!
</Pascal>

André R.

Monday 09 February 2009 10:37:38 am

Suggestion:
<custom name="is_member">
Content for member
</custom>

I have never tried to have a if in one template and the end of the if in the other, but I guess you get an error when you do it?

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Pascal Specht

Tuesday 10 February 2009 1:52:59 am

Hi André,

Thanks for your reply. Unfortunately, the <custom name="isMember">Content for member
</custom> suggestion does not work as expected: as soon as the content is for example a table with nested cells etc., when activating and deactivating the editor, I loose all the code between the XML markup (Content for member
). I'm under eZ Publish 3.9.3 and can't migrate this project. I'm now searching other ways to achieve it, but if you got other ideas they are greatly welcome!

Thanks in advance,
</Pascal>

Pascal Specht

Wednesday 11 February 2009 12:53:26 am

I didn't find a smart solution for this. But if anyone faces the same problem (having different content on the home page depending on the user belonging to a group or another) I ended up with this 'hack': I added code at the beginning of the frontpage template. This code checks if the rendered page is node 2 (home page) and if the user is belonging to a special group. If both conditions are met, it swaps the homepage node with another frontpage node (SpecialGroupHome). Not very nice, but works as intended.

</Pascal>

{if eq($node.node_id,2)}
{if userInSpecialGroup( ) }
{def $frontpages=fetch( content, list, hash( parent_node_id, 2,
                                               class_filter_type, include,
                                               class_filter_array, array('frontpage')
                                           ) )}
{foreach $frontpages as $fp}
{if eq($fp.name,'SpecialGroupHome')}
{set $node=$fp }
{/if}
{/foreach}
{/if}
{/if}