Dynamic right column

Author Message

Yngve Bergheim

Tuesday 04 October 2005 4:39:27 am

My goal: I want to show dynamic content in the right column (where Latest News now is shown), which can be unique to each folder. Let's say you have a "home/Sports" folder, and you want to display sport articles in both the main area and the right column. In a "home/Science" folder you want to display just science articles in main and right column. In folder "home/Sports/Soccer" you don't have a soccer right column, so you display the parent's right column, Sports.

Ok, still with me?

I'm a looser in the eZ template language so I'm not near any solution jet, but I guess this might be a good start:

In every folder look for a child folder called "RightColumn". If not found, look for, the "RightColumn" folder in parent folder, if not found, look in grand parent folder etc. When found, get all the children in that folder and display them.

Can someone please help me in the right direction in the template language?

Yngve Bergheim

Tuesday 04 October 2005 4:43:56 am

And I was thinking of setting the "RightColumn" folder to be hidden, so it doesn't show in the main content.

Matt Reston

Tuesday 04 October 2005 10:32:58 am

Excellent. Unfortunately i can't help you with this, but i was about to post the very same question and also await any information people can provide.

Yngve Bergheim

Wednesday 05 October 2005 2:45:19 am

Okey, my first try:

{* set children variable *}
{let children=fetch('content',tree,hash(parent_node_id,$module_result.node_id,
	                     class_filter_type,  include,
                           class_filter_array, array( 'folder' ),
	))}

{* loop children *}
{section name=Child loop=$children}
	
	{* If we find folder RightColumn *}
	{if eq( $Child:item.name, 'RightColumn' )}
		
		Test: {$Child:item.name}<br>			

		{let thischildren=fetch('content',tree,hash(parent_node_id,$Child:item.node_id))}
		Test: thischildren{$thischildren:item|attribute(show)}	
			<h1>{$Child:item.node_id}{$Child:item.name}</h1>
					
			{* Loop trough content inside RightColumn folder *}
			{section name=subchild loop=$thischildren}
			Test: subchild
					{$subchild:item|attribute(show)}	
					{$subchild:item.name}<br>
			{/section}
		
		{/let}		
		
	{/if}
{/section}

{/let}

It produce:

Test: RightColumn
Test: thischildren
Attribute	Type	Value	
116RightColumn

So $thischildren is never set. Why? I have content inside mye RightColumn folder. Is it not possible to have a nested loop?

Roy Bøhmer

Thursday 06 October 2005 3:15:33 am

I've once done a similar task. The way I solved it was to make a seperate class (named 'sidebox' or something). The template logic is pretty much the same you describe. The main advantage (i think) is that by doing this
- you can add additional features to the content presented, by adding optional attributes to the class.
- its esier to fetch nodes from a spesific class, rather than match the name.
- you dont have to hide the node, but just assure that none of the class-attributes is searchable, and that there are no useful template to view its content for the user.

Instead of making a brand new class you can add an attribute to the folder-class, determing if dynamic right column content is to be shown for this folder. The point is: I would not recomend making a folder-node with more or less "dummy-content" to add funcionality.

To comment on your code-sample:
First: It looks like you first looks for 'RightColumn'-folders in parent-node. Then, if it finds one, try to fetch children to the 'RightColumn'-folder. If I have understood the consept of 'RightColumn'-folders, it probably dont have any children.
Seccond:

Test: thischildren{$thischildren:item|attribute(show)}

should be

Test: thischildren{$thischildren.0|attribute(show)}

$thischildren is an array (since you used fetch,tree). It's only when you do a loop (section) you need the .item.

Hope it helps!
Roy

 

Yngve Bergheim

Thursday 06 October 2005 6:07:04 am

Thank you very much. Your answer is appreciated!

Your idea is very good.

I can just make a sidebar class (copy the folder class), and then the sidebar-folder will display all the children nodes in the right column. I'll definitively go for that. Thanks!

Your code

Test: thischildren{$thischildren.0|attribute(show)}

Didn't work for me.

Any idea of how I can go reverse in the nodes? If I don't find a sidebar class in the current folder I would like to fetch a sidebar in parent node, grandparent... etc.

Roy Bøhmer

Thursday 06 October 2005 2:44:59 pm

At least in pagelayout you have $module_result.path which is an array containing (among other) node_id. You find something similar in $node.'something'. When you know each node_id in the path, you can do some fetching and tests to find the latest folder with a sidebar-class child.

It's late, and I already should have gone to bed, so sorry for not posting any code.

Roy

Yngve Bergheim

Friday 14 October 2005 2:17:21 am

Wow. It works!

This is how you can make dynamic right column;

1. Make a sidebar class (copy the folder class)
2. Put the sidebar code below in your right column template file (to try it quick and dirty, add it in design/standard/templates/toolbar/full/node_list.tpl
3. The sidebar-folder will display all the children nodes in the right column.
4. Modify your folder.tpl so it does not show sidebar classes: Add the following code in &#8220;set list_items=fetch_alias(&#8230;&#8221;

class_filter_type, exclude,
class_filter_array, array( 'sidebar' ),

Sidebar code:

{def $thisNode=$node}
{def $thisParent=$thisNode.node_id}
{def $isSidebar=false() }
{def $i=0 }

{* Loop untill we find a sidebar *}
{while ne($isSidebar,true() )  }

	{* Make sure we don't walk up the node tree more then 4 times *}
	{if ne($i,4)}	
		
		{* Fetch current node and make sure sidebar is a children *}	
		{let Children=fetch('content', 'list', 
					hash('parent_node_id', $thisParent,
					'depth', 1,
					class_filter_type, include,
					class_filter_array, array( 'sidebar' ),
				))}
				
			{* If this node got a sidebar, print it *}
			{if eq($:Children.0.name,'Sidebar') }
				{section var=childrenList loop=$Children}
					{node_view_gui view=full content_node=$childrenList}
					{set $isSidebar=true() }
			    {/section}
			{else}
			    {set $thisParent=$thisNode.node_id}
			    {* If this node not is the root node, get parent node *}
			    {if ne($thisNode.node_id,1) }
   			    	{set $thisNode=fetch('content','node',hash('node_id',$thisNode.parent_node_id))}
   			    {else}
   			    	{set $isSidebar=true()}
   			    {/if}
		    {/if}
		{/let}
		
		{set i=$i|inc}
	{else}
		{set $isSidebar=true()}
	{/if}
{/while}			
		
{undef $thisNode}
{undef $isSidebar}	
{undef $thisParent}

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 20:49:01
Script start
Timing: Jan 18 2025 20:49:01
Module start 'layout'
Timing: Jan 18 2025 20:49:01
Module start 'content'
Timing: Jan 18 2025 20:49:02
Module end 'content'
Timing: Jan 18 2025 20:49:02
Script end

Main resources:

Total runtime0.9990 sec
Peak memory usage4,096.0000 KB
Database Queries74

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0079 589.0391152.6250
Module start 'layout' 0.00790.0038 741.664139.4453
Module start 'content' 0.01170.9860 781.1094578.0938
Module end 'content' 0.99770.0013 1,359.203120.1719
Script end 0.9989  1,379.3750 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.3461160.0002
Check MTime0.00140.1373160.0001
Mysql Total
Database connection0.00090.089710.0009
Mysqli_queries0.928392.9302740.0125
Looping result0.00080.0840720.0000
Template Total0.962196.320.4810
Template load0.00200.201020.0010
Template processing0.960096.104320.4800
Template load and register function0.00030.025410.0003
states
state_id_array0.00110.106710.0011
state_identifier_array0.00080.084720.0004
Override
Cache load0.00180.1832560.0000
Sytem overhead
Fetch class attribute can translate value0.00080.075630.0003
Fetch class attribute name0.00170.170680.0002
XML
Image XML parsing0.00050.051730.0002
class_abstraction
Instantiating content class attribute0.00000.001680.0000
General
dbfile0.00080.0794100.0001
String conversion0.00000.001040.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
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
17content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/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: 38
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs