Forums / Install & configuration / Fetching articles from subfolders

Fetching articles from subfolders

Author Message

Runar Ingebrigtsen

Wednesday 24 November 2004 3:30:25 am

I've got a news folder with several subfolders containing the actual articles. I'm trying to fetch the subfolders first, then the articles by doing a loop in a loop.

I've just started understanding the template language, so I'm not perfectly capable of understanding everything yet. Am I thinking imperfectly here or am I just not getting the correct strings?

{let subfolder=fetch( content,
	list,
		hash( 'parent_node_id', 80,
		class_filter_type, include,
		class_filter_array, array( 'folder' )
		)
	)
}
{* Loop through all subfolders that we just fetched. *}
{section name=Sub loop=$subfolder}
	{let children=fetch( content,
		list,
		hash( 'parent_node_id', $node.node_id,
			class_filter_type, include,
			class_filter_array, array( 'article' )
			)
		)
	}
	{* Loop through all articles that we just fetched. *}
	{section name=Child loop=$children}
		<li>
		{* Display a link to the article. *}
			<a href={$:item.url_alias|ezurl}>{$:item.name}</a>
		</li>
	{* End of loop. *}
	{/section}
{/section}
{/let}

Runar Ingebrigtsen

Wednesday 24 November 2004 4:20:23 am

Solved. :)

{* Fetch all subfolders, each representing a news category *}
{let subfolders=fetch( content,
	list,
		hash( 'parent_node_id', 80,
		class_filter_type, include,
		class_filter_array, array( 'folder' )
		)
	)
}
{* For each subfolder, fetch the articles *}
{section loop=$subfolders}
{let articles=fetch( content,
	list,
		hash( 'parent_node_id', $:item.node_id,
		class_filter_type, include,
		class_filter_array, array( 'article' )
		)
	)
}
	{* For each article, display the name and the url to the article and the category *}
	{section loop=$articles}
	<li>
		<a href={$:item.url_alias|ezurl}>{$:item.name}</a> - <a class="category" href={$:item.parent.url_alias|ezurl}>{$:item.parent.name}
	</li>
	{/section}
	{/let}
{/section}
{/let}

Martin Leblanc

Monday 20 December 2004 4:13:44 am

It helps if you indent the code correctly.... Then it's easy to see that a {/let} is missing.

Martin Leblanc

View this in Firefox: www.biocandy.dk/test.html

http://www.opensystems.dk
http://www.site-camp.net

Roy Bøhmer

Monday 20 December 2004 11:40:06 am

Agree with Martin, but fetching $node.node_id instead of $:item.node_id may caused more trouble than the missing /let ...
Personally I think it's easier to grasp the {section} when I use the var-attribute:

{section var=folder loop=$subfolders}
   Node-id of subfolder: {$folder.item.node_id}<br>
{/section}

Especially when doing nested loops I find this easier. There might be som drawbacks due to the namespace-stuff, but in case you had missed the var-feature at least check it out!

Good luck!
Roy

eZ debug

Timing: Jan 18 2025 22:21:27
Script start
Timing: Jan 18 2025 22:21:27
Module start 'content'
Timing: Jan 18 2025 22:21:27
Module end 'content'
Timing: Jan 18 2025 22:21:27
Script end

Main resources:

Total runtime0.5719 sec
Peak memory usage4,096.0000 KB
Database Queries63

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0059 587.8359180.8203
Module start 'content' 0.00590.5614 768.6563586.9453
Module end 'content' 0.56730.0045 1,355.601646.0859
Script end 0.5718  1,401.6875 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00300.5293140.0002
Check MTime0.00130.2295140.0001
Mysql Total
Database connection0.00060.097410.0006
Mysqli_queries0.530292.7034630.0084
Looping result0.00050.0896610.0000
Template Total0.546295.520.2731
Template load0.00210.362220.0010
Template processing0.544195.141820.2721
Template load and register function0.00010.026210.0001
states
state_id_array0.00040.062110.0004
state_identifier_array0.00090.149120.0004
Override
Cache load0.00170.2995190.0001
Sytem overhead
Fetch class attribute can translate value0.00070.117930.0002
Fetch class attribute name0.00090.162350.0002
XML
Image XML parsing0.00230.401530.0008
class_abstraction
Instantiating content class attribute0.00000.005050.0000
General
dbfile0.00240.4226190.0001
String conversion0.00000.000930.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
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 18
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs