ez.no / ezpublish / documentation / customization / tips & tricks / one article folder
These documentation pages are no longer maintained. Please visit the new documentation site.
You have a folder with just one article. If someone goes into this folder, you want to show the article directly. If there are more articles than one, you want to show the user a list of these articles.
To apply below solutions you will have to put the code into an override template for the folder class full view. I.e. this means you create a template which consists of the code from below, put it into /design/yourdesign/override/templates and in your override.ini.append point to this new template for class id 2 (folder). See what exactly to put in the override.ini.append.
Use this code:
{* Get the articles (ClassID: "2"! Might be different for you!) *} {let articles=fetch('content','list',hash(parent_node_id,$node.node_id,class_filter_type,"include",class_filter_array,array(2)))} {* Get a count of the articles (ClassID: "2"! Might be different for you!) in this folder. *} {let articles_count=fetch('content','list_count',hash(parent_node_id,$node.node_id,class_filter_type,"include",class_filter_array,array(2)))} {* Now decide what to do *} {switch name=decision match=$articles_count} {case match=1} {* Show this if there is only one article! E.g. include the "full article view" page. *} {section name=Article loop=$articles} {node_view_gui view=full content_node=$decision:Article:item} {/section} {/case} {case} {* Show this for more than one article. *} {section name=Article loop=$articles} <h3>{$decision:Article:item.name}</h3> {$decision:Article:item.data_map.intro.data_text}<br /><br /> {section name=read_link show=$decision:Article:item.contentobject_version_object.data_map.body} <a href={concat("/content/view/full/",$decision:Article:item.node_id)|ezurl}>Read more...</a> {/section} <hr /> {/section} {/case} {/switch}
Another solution that may be better in terms of speed, depending upon your site design. The difference here is the use of the keyword 'limit' which will limit the number of articles to be returned. For example, the code given below will only return a single article and display it. (Difference to solution 1: this solution will always show just 1 article. Solution 1 will show all articles if there are more than 1.)
{let articles=fetch(content, list, hash(parent_node_id, $node.node_id, limit, 1, class_filter_type, "include", class_filter_array, array(2))) } {section name=Article loop=$articles} {node_view_gui view=full content_node=$Article:item} {/section} {/let}
You need two steps:
For 3.4 and the new demo folder full view use:
design/news/override/templates/full/folder.tpl
{* Folder - Full view *} <div class="content-view-full"> <div class="class-folder"> {section show=is_unset( $versionview_mode )} {*start 1*} {section show=$node.object.data_map.show_children.content} {let page_limit=10 list_items=array() list_count=0} {section show=or( $view_parameters.day, $view_parameters.month, $view_parameters.year )} {let time_filter=array( and, array( 'published', '>=', maketime( 0, 0, 0, $view_parameters.month, cond( $view_parameters.day, $view_parameters.day, 1 ), $view_parameters.year ) ), array( 'published', '<=', maketime( 23, 59, 59, cond( $view_parameters.day, $view_parameters.month, $view_parameters.month|inc ), cond( $view_parameters.day, $view_parameters.day, 0 ), $view_parameters.year ) ) )} {set list_items=fetch_alias( folder_children, hash( parent_node_id, $node.node_id, offset, $view_parameters.offset, attribute_filter, $time_filter, sort_by, $node.sort_array, limit, $page_limit ) ) list_count=fetch_alias( folder_children_count, hash( parent_node_id, $node.node_id ) )} {/let} {section-else} {set list_items=fetch_alias( folder_children, hash( parent_node_id, $node.node_id, offset, $view_parameters.offset, sort_by, $node.sort_array, limit, $page_limit ))} {set list_count=fetch_alias( folder_children_count, hash( parent_node_id, $node.node_id ) )} {/section} <div class="content-view-children"> {switch match=$list_count} {* If only one article in folder: display this in full article view *} {case match=1} {/case} {* If more than one article in folder: display list of articles in line view *} {case} <h1>{$node.object.data_map.name.content|wash()}</h1> {section show=$node.object.data_map.short_description.content.is_empty|not} <div class="attribute-short"> {attribute_view_gui attribute=$node.object.data_map.short_description} </div> {/section} {section show=$node.object.data_map.description.content.is_empty|not} <div class="attribute-long"> {attribute_view_gui attribute=$node.object.data_map.description} </div> {/section} {/case} {/switch} {section var=child loop=$list_items sequence=array(bglight,bgdark)} {switch match=$list_count} {* If only one article in folder: display this in full article view *} {case match=1} {node_view_gui view=full content_node=$child} {/case} {* If more than one article in folder: display list of articles in line view *} {case} {node_view_gui view=line content_node=$child} {/case} {/switch} {/section} </div> {include name=navigator uri='design:navigator/google.tpl' page_uri=$node.url_alias item_count=$list_count view_parameters=$view_parameters item_limit=$page_limit} {/let} {/section} {section-else} {*else 1*} <h1>{$node.object.data_map.name.content|wash()}</h1> {section show=$node.object.data_map.short_description.content.is_empty|not} <div class="attribute-short"> {attribute_view_gui attribute=$node.object.data_map.short_description} </div> {/section} {section show=$node.object.data_map.description.content.is_empty|not} <div class="attribute-long"> {attribute_view_gui attribute=$node.object.data_map.description} </div> {/section} {/section}{*end 1 *} </div> </div>
and because auf the fetch_alias you need to add these lines to your
settings/siteaccess/news/fetchalias.ini.append.php
[folder_children] Constant[sort_by]=priority;0 Parameter[parent_node_id]=parent_node_id Parameter[offset]=offset Parameter[limit]=limit Constant[class_filter_type]=exclude Constant[class_filter_array]=folder Module=content FunctionName=list [folder_children_count] Parameter[parent_node_id]=parent_node_id Module=content FunctionName=list_count Constant[class_filter_type]=exclude Constant[class_filter_array]=folder
Comments
Simplifying...
Restrepo John
Monday 28 July 2003 5:23:39 pm
Thanks for the tip EzCrew,
{* Folder template *}
{default with_children=true()}
{let page_limit=20
articles_count=and( $with_children, fetch( content, list_count, hash(
parent_node_id, $node.node_id,
class_filter_type, exclude,
class_filter_array, array( 1, 10 ) ) ) )}
{default content_version=$node.contentobject_version_object}
<div class="block">
{attribute_view_gui attribute=$content_version.data_map.description}
</div>
{section show=$with_children}
{section name=Child loop=fetch(content, list, hash(
parent_node_id, $node.node_id,
limit, $page_limit,
offset, $view_parameters.offset,
sort_by, $node.sort_array,
class_filter_type, exclude,
class_filter_array, array( 1, 10 ) ) )}
{switch match=$articles_count}
{* If only one article in folder: display this in full article view *}
{case match=1}
{node_view_gui view=full content_node=$Child:item}
{/case}
{* If more than one article in folder: display list of articles in line view *}
{case}
{node_view_gui view=line content_node=$Child:item}
{/case}
{/switch}
{/section}
{/section}
{/default}
{/let}
{/default}
Thanks, your addon gave me some ideas and I ended up with this:
Valentin Svelland
Monday 14 July 2003 9:56:13 am
{* Get the articles (ClassID: "2"! Might be different for you!) *}
{let articles=fetch('content','list',hash(parent_node_id,$node.node_id,class_filter_type,"include",class_filter_array,array(2)))}
{* Get a count of the articles (ClassID: "2"! Might be different for you!) in this folder. *}
{let articles_count=fetch('content','list_count',hash(parent_node_id,$node.node_id,class_filter_type,"include",class_filter_array,array(2)))}
{* Now decide what to do *}
{switch name=decision match=$articles_count}
{* If only one article in folder: display this in full article view *}
{case match=1}
{* Show this if there is only one article! E.g. include the "full article view" page. *}
{section name=Article loop=$articles}
{node_view_gui view=full content_node=$decision:Article:item}
{/section}
{/case}
{* If two or more articles: display this according to "line_article.tpl"-view *}
{case}
{section name=Article loop=$articles}
{node_view_gui view=line content_node=$decision:Article:item}
{/section}
{/case}
{/switch}
Added missing info on how to apply
Karsten Jennissen
Friday 11 July 2003 3:52:13 pm
But where does the code go?
Valentin Svelland
Friday 11 July 2003 3:39:11 pm
Also I think this feature should be considered included in the v.3.2 admin. Quite often I don't need childarticles and therefore no newslisting in my folders. Still, this CMS-engine rules! Keep up the good work.