Fetching data from nodes

Author Message

Frode Slettum

Saturday 19 August 2006 11:54:07 am

Hi

I'm making an intranet site and I want to accomplish the following:
- Have a frontpage (node 2) that displays the 5 latest object from all top-nodes
- When entering a top-node, the frontpage on each top-node should have it's own frontpage that displays the 5 latest objects from all sub-nodes.

I have read the Main override template by Bård Farstad but this only fetches articles from a certain node.

The bundled template full/folder.tpl does goes through all nodes (folders) but this is written with the old template language.

So, I want to make a template override that's searching all nodes (folders) and displays the 5 latest objects from each folder using the new template language.

regards
Frode Slettum

Claudia Kosny

Sunday 20 August 2006 1:14:54 am

Hi Frode,

I have to admit that I am not sure what you mean by old and new template language, but here my idea on how to do this (please node that the code is not tested and may contain some typos):
- Have a frontpage (node 2) that displays the 5 latest object from all top-nodes

{* fetch all top nodes that are folders *}
{def $topNodesArr = ('content', 'list', hash('parent_node_id', $node.node_id,
                                             'class_filter_type',  'include',
                                             'class_filter_array', array('folder')))
     $subNodesArr = array()}

{* now loop through all these top nodes and fetch the 5 latest objects *}
{foreach $topNodesArr as $topNode}
 {set $subNodesArr = ('content', 'list', hash('parent_node_id', $topNode.node_id,
                                              'sort_by', array('published', false()),
                                              'limit', 5))}
 {foreach $subNodesArr as $subNode}
   {* display the node *}
   {node_view_gui view=line content_node=$subNode}
   {* or just link to the subnode *}
   <a href={$subNode.url_alias|ezurl()}>{$subNode.name}</a><br />
 {/foreach}
{/foreach}

 

You will have to override the default folder template with the the code above and set an override match condition that matches node 2.

Please note that this feteches the 5 latest children of the respective node. If you interested in the 5 latest nodes that are somewhere below the respective node, you have to replace the fetch function 'list' by 'tree'.

Now the second part:
- When entering a top-node, the frontpage on each top-node should have it's own frontpage that displays the 5 latest objects from all sub-nodes.
The template code is the same as above.

Then you will have to create an override which matches all folders that have 2 as parentnode, so the match conditions should be like this:
Match[class_identifier]=folder
Match[parent_node]=2

This way you have both the frontpage (node 2) and the direct subnodes (that are folders) displaying the five latest subnodes, all other folders still use the default template.

If the code above is what you consider old template language please give me a link to some information about the new language so I can learn how to do it.

Greetings from Luxembourg

Claudia

Frode Slettum

Sunday 20 August 2006 5:17:52 am

Thank you a lot. I'll test it very soon.

NB! You are using the new template language. The old language does not use "def" and so on, but "let", "section" and some other shit :) (I think)

Frode Slettum

Monday 21 August 2006 11:21:44 pm

Thank you a lot, this code helped me a lot! :)

Just had to add "fetch" a couple of places, except that it worked just like I'd hoped.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.