User managed use of template

Author Message

Etienne Jolivet

Monday 07 April 2008 7:50:39 am

Hi

I use a Folder content class. There are three different ways of displaying the folder (let's say one without the children, one whith the children, and the last one with children and grandchildren).
I want THE EDITOR to be able to chose in which way the folder he is editing should be displayed. Is there a way to do that ? I mean, a better way than :
- creating three different content classes and set up three override conditions
- setting up one override condition and put "if" operators in my template...

Thank you very much for your help !

Etienne

Mark Marsiglio

Monday 07 April 2008 12:51:19 pm

We did this by adding an attribute to the folder class that is a Select, with three choices. 1) Don't Show Children, 2) Show Children, 3) Shown Children and Grandchildren. Then this is our template code for the display of children in full/folder.tpl:

{def  $include_classes=array('section_home', 'folder', 'calendar', 'article','faq_list','feedback_form','file','link')
	$my_children=fetch('content', 'list', hash('parent_node_id', $node.object.main_node_id, 'class_filter_type', 'include', 'class_filter_array', $include_classes, sort_by, $node.sort_array ))
	$kidshowset=$node.data_map.show_children.content.0
	$url_string=''
	$short_text_at=array()}
{if gt($my_children|count, 0)}
<div class='showsubitems'>
{/if}
    {if and(gt($my_children|count, 0), ne($kidshowset,0) )}
	{section var=this_child loop=$my_children}
	{if ne(24, $this_child.object.section_id)}

	   {set url_string=and(is_set($this_child.data_map.link), is_set($this_child.data_map.url), $this_child.data_map.link.data_int)|choose(fetch(content, node, hash(node_id, $this_child.object.main_node_id)).url_alias|ezroot(no),$this_child.data_map.url.content|ezroot(no))
		  short_text_at = first_set($this_child.object.data_map.short_description, $this_child.object.data_map.summary ,$this_child.object.data_map.intro, $this_child.object.data_map.answer, false())}

	   {if gt($kidshowset,1)}

	   {if $short_text_at.has_content}
	   <h2><a href='{$url_string}'>{first_set($this_child.data_map.namelong.content,$this_child.name)|wash}</a></h2>

{/if}
	   
	   {let grand_children=fetch('content', 'list', hash(parent_node_id, $this_child.object.main_node_id, sort_by, $this_child.sort_array, class_filter_type, 'include', 'class_filter_array', $include_classes))}
		<ul class='sectionhomesubitems'>
		{foreach $grand_children as $this_grandchild}
		   {if ne(24, $this_grandchild.object.section_id)}
	     	   {set url_string=and(is_set($this_grandchild.data_map.link), is_set($this_grandchild.data_map.url), $this_grandchild.data_map.link.data_int)|choose($this_grandchild.url_alias|ezroot(no),$this_grandchild.data_map.url.content|ezroot(no))}
		   <li><a href='{$url_string}'>{$this_grandchild.name|wash}</a></li>
		   {delimiter}|{/delimiter}
		   {/if}
		{/foreach}
		</ul>
	   {/let}

	   {else}

	   <h2><a href='{$url_string}'>{$this_child.name|wash}</a></h2>
 	   <div class="divdesc-perm">{attribute_view_gui attribute=$short_text_at}</div>

	   {/if}
	{/if}
	{/section}
    {/if}
{if gt($my_children|count, 0)}
</div>
{/if}
{undef}

--WARNING - I did not clean out some site specific stuff in this code that you might be able to safely remove because it dealt with a specific section override on our site.

http://www.thinkcreative.com
Turning Ideas Into Strategic Solutions

Etienne Jolivet

Tuesday 08 April 2008 5:01:17 am

Thank you for your answer!

I was hoping that maybe eZ offered something to do this with configuration files... Too bad :)

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 18:43:24
Script start
Timing: Jan 18 2025 18:43:24
Module start 'layout'
Timing: Jan 18 2025 18:43:24
Module start 'content'
Timing: Jan 18 2025 18:43:24
Module end 'content'
Timing: Jan 18 2025 18:43:24
Script end

Main resources:

Total runtime0.0187 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0054 587.9141152.6250
Module start 'layout' 0.00540.0055 740.539139.4453
Module start 'content' 0.01090.0056 779.984493.4453
Module end 'content' 0.01650.0022 873.429734.3047
Script end 0.0187  907.7344 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002613.6934140.0002
Check MTime0.00115.8803140.0001
Mysql Total
Database connection0.00094.624710.0009
Mysqli_queries0.003317.843230.0011
Looping result0.00000.224110.0000
Template Total0.00179.210.0017
Template load0.00094.556010.0009
Template processing0.00094.662910.0009
Override
Cache load0.00063.081510.0006
General
dbfile0.00031.426180.0000
String conversion0.00000.057340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs