Path

ez.no / ezpublish / documentation / customization / tips & tricks / one article folder


One Article Folder

These documentation pages are no longer maintained. Please visit the new documentation site.

Situation:

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.

Solution 1:

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}

Solution 2:

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}

Solution 3 for 3.4:

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...

Modify your ./mydesign/override/folder.tpl to content these lines and you're done. Note that is pretty much the same as the original folder.tpl, except that if there's only one article it shows it in full view and if there's more than one article it shows them in line view.
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:


{* 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

At the beginning I added a small paragraph on how to use these code snippets. Hope this helps.

But where does the code go?

I've poked around for some time with these snippets and can't seem to get it right. Which files do I need to mod in my /design- and /settings-folders to succeed?

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.

Contents

Customization

Access control
eZ publish API Documentation
Content structure
Custom design
Components
Tips & Tricks
    Debugging templates
    Javascript in templates
    Fetching current user
    Showing related objects
    Show which templates are used
    Fetching the ID of the parent
    One Article Folder
    Creating tree menus
    How can I use my own php script insid...
    Hiding attribute content
    Splitting an article over several pages
    Accessing section id in pagelayout
    List articles in folder
    Creating nice URLs
    Alt tag on images
    Improve the pagelayout.tpl
    Clean HTML tags
    Insert javascript call inside ezpub d...
    3rd party applications
    Fetch Function examples
    Display more than 15 items on your co...
    Including PHP files in templates
    Redirecting after content publishing
    HowTo see if article has an image
    Date and Time Formats
    Forms processing example: store user...
    Adjust Timezone
    Adding a Remove Button/Image
    Find the age in years for an object
    Editing, creating and removing conten...
    Indexing binary files with IFilters o...
Troubleshooting


Created

21/04/2003
4:17:18 am
by Kai Duebbert

Last updated

01/09/2004
1:09:54 pm
by Ekkehard Dörre

Authors

Kai Duebbert
Bård Farstad
Karsten Jennissen
Ekkehard Dörre



This page is part of the eZ Publish documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.