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}

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 15:19:35
Script start
Timing: Jan 18 2025 15:19:35
Module start 'layout'
Timing: Jan 18 2025 15:19:35
Module start 'content'
Timing: Jan 18 2025 15:19:36
Module end 'content'
Timing: Jan 18 2025 15:19:36
Script end

Main resources:

Total runtime0.8799 sec
Peak memory usage4,096.0000 KB
Database Queries60

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 588.0469152.6406
Module start 'layout' 0.00580.0040 740.687539.4766
Module start 'content' 0.00970.8687 780.1641565.4063
Module end 'content' 0.87850.0014 1,345.570312.1250
Script end 0.8799  1,357.6953 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.4023160.0002
Check MTime0.00150.1649160.0001
Mysql Total
Database connection0.00080.086510.0008
Mysqli_queries0.825293.7884600.0138
Looping result0.00050.0594580.0000
Template Total0.845296.120.4226
Template load0.00200.232520.0010
Template processing0.843195.819320.4216
Template load and register function0.00010.010710.0001
states
state_id_array0.00090.099810.0009
state_identifier_array0.00130.147920.0007
Override
Cache load0.00170.1947340.0001
Sytem overhead
Fetch class attribute can translate value0.00100.109220.0005
Fetch class attribute name0.00120.131860.0002
XML
Image XML parsing0.00090.100020.0004
class_abstraction
Instantiating content class attribute0.00000.002080.0000
General
dbfile0.00080.0941230.0000
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 27
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs