Forums / Setup & design / Fetching data from nodes

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.

eZ debug

Timing: Jan 18 2025 14:58:14
Script start
Timing: Jan 18 2025 14:58:14
Module start 'content'
Timing: Jan 18 2025 14:58:15
Module end 'content'
Timing: Jan 18 2025 14:58:15
Script end

Main resources:

Total runtime1.5484 sec
Peak memory usage4,096.0000 KB
Database Queries197

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 587.7109180.8359
Module start 'content' 0.00571.2980 768.5469532.3672
Module end 'content' 1.30360.2447 1,300.9141336.7500
Script end 1.5483  1,637.6641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00370.2395210.0002
Check MTime0.00140.0873210.0001
Mysql Total
Database connection0.00070.043710.0007
Mysqli_queries1.464294.56671970.0074
Looping result0.00240.15501950.0000
Template Total1.520198.220.7600
Template load0.00170.110620.0009
Template processing1.518398.060220.7592
Template load and register function0.00010.009010.0001
states
state_id_array0.00110.073310.0011
state_identifier_array0.00160.101720.0008
Override
Cache load0.00140.0932390.0000
Sytem overhead
Fetch class attribute can translate value0.00180.114330.0006
Fetch class attribute name0.00160.105450.0003
XML
Image XML parsing0.00210.134530.0007
class_abstraction
Instantiating content class attribute0.00000.000970.0000
General
dbfile0.00740.4787270.0003
String conversion0.00000.000330.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs