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.

eZ debug

Timing: Jan 31 2025 03:30:32
Script start
Timing: Jan 31 2025 03:30:32
Module start 'layout'
Timing: Jan 31 2025 03:30:32
Module start 'content'
Timing: Jan 31 2025 03:30:33
Module end 'content'
Timing: Jan 31 2025 03:30:33
Script end

Main resources:

Total runtime1.2602 sec
Peak memory usage8,192.0000 KB
Database Queries60

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0050 588.1328151.2109
Module start 'layout' 0.00500.0034 739.3438220.6875
Module start 'content' 0.00841.2510 960.03134,434.7500
Module end 'content' 1.25940.0008 5,394.781311.8516
Script end 1.2602  5,406.6328 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.2623160.0002
Check MTime0.00130.1001160.0001
Mysql Total
Database connection0.00070.057910.0007
Mysqli_queries1.170192.8468600.0195
Looping result0.00050.0404580.0000
Template Total1.200495.320.6002
Template load0.00230.180420.0011
Template processing1.198195.073320.5991
Template load and register function0.00130.106210.0013
states
state_id_array0.00430.339310.0043
state_identifier_array0.00270.210820.0013
Override
Cache load0.00190.1546390.0000
Sytem overhead
Fetch class attribute can translate value0.00170.136120.0009
Fetch class attribute name0.00200.162150.0004
XML
Image XML parsing0.00190.148020.0009
class_abstraction
Instantiating content class attribute0.00000.001170.0000
General
dbfile0.00290.2266160.0002
String conversion0.00000.000540.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
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs