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

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 06:29:28
Script start
Timing: Jan 31 2025 06:29:28
Module start 'layout'
Timing: Jan 31 2025 06:29:28
Module start 'content'
Timing: Jan 31 2025 06:29:28
Module end 'content'
Timing: Jan 31 2025 06:29:28
Script end

Main resources:

Total runtime0.0127 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0055 588.2578151.2266
Module start 'layout' 0.00550.0019 739.484436.6797
Module start 'content' 0.00750.0040 776.164194.3125
Module end 'content' 0.01150.0012 870.476633.9922
Script end 0.0126  904.4688 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002116.7772140.0002
Check MTime0.00108.0063140.0001
Mysql Total
Database connection0.00129.669310.0012
Mysqli_queries0.001814.321230.0006
Looping result0.00000.086610.0000
Template Total0.00097.110.0009
Template load0.00075.751810.0007
Template processing0.00021.335310.0002
Override
Cache load0.00054.164210.0005
General
dbfile0.00107.876380.0001
String conversion0.00000.054640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs