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}

eZ debug

Timing: Jan 18 2025 10:33:15
Script start
Timing: Jan 18 2025 10:33:15
Module start 'content'
Timing: Jan 18 2025 10:33:15
Module end 'content'
Timing: Jan 18 2025 10:33:16
Script end

Main resources:

Total runtime0.7098 sec
Peak memory usage4,096.0000 KB
Database Queries197

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0070 587.8438180.8125
Module start 'content' 0.00710.5808 768.6563570.5000
Module end 'content' 0.58790.1218 1,339.1563336.7422
Script end 0.7097  1,675.8984 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00400.5611210.0002
Check MTime0.00150.2090210.0001
Mysql Total
Database connection0.00120.165410.0012
Mysqli_queries0.635789.55931970.0032
Looping result0.00190.26071950.0000
Template Total0.685796.620.3429
Template load0.00190.272720.0010
Template processing0.683896.336020.3419
Template load and register function0.00010.010710.0001
states
state_id_array0.00080.109910.0008
state_identifier_array0.00070.094320.0003
Override
Cache load0.00170.2330340.0000
Sytem overhead
Fetch class attribute can translate value0.00150.211730.0005
Fetch class attribute name0.00100.134760.0002
XML
Image XML parsing0.00100.138330.0003
class_abstraction
Instantiating content class attribute0.00000.002880.0000
General
dbfile0.00230.3183340.0001
String conversion0.00000.000930.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 27
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs