Fetching nodes and lists
This page is for designers who fetch pages and lists of pages. All parameters below are from
kernel/content/function_definition.php.
Contents
One node
def $home = fetch( 'content', 'node', hash( 'node_id', 2 ) )
def $about = fetch( 'content', 'node', hash( 'node_path', 'about-us' ) )
def $info = fetch( 'content', 'node', hash( 'remote_id', 'mytheme-site-info' ) )Parameters: node_id, node_path, remote_id, language_code. The result is false when the node does not exist or
may not be read.
Children: list
{def $children = fetch( 'content', 'list', hash( 'parent_node_id', $node.node_id,
'sort_by', $node.sort_array,
'class_filter_type', 'include',
'class_filter_array', array( 'article', 'blog_post' ),
'offset', $offset,
'limit', 10 ) )}| Parameter | Meaning |
|---|---|
parent_node_id | whose children (required) |
sort_by | sort fields (Fetch filters and sorting); $node.sort_array uses the order the editor set |
offset, limit | paging |
class_filter_type, class_filter_array | include or exclude these class identifiers |
attribute_filter, extended_attribute_filter | filter on field values or custom joins |
depth, depth_operator | for tree: how deep |
main_node_only | only the main location of each object |
ignore_visibility | include hidden nodes (avoid in public designs) |
only_translated, language | language handling |
objectname_filter | names starting with a letter (A to Z lists) |
group_by, limitation, as_object, load_data_map | advanced: grouping, permission override, plain arrays, whether field data is loaded at once |
Descendants: tree
The same parameters, for every level below the parent; with depth to limit it:
{def $all_articles = fetch( 'content', 'tree', hash( 'parent_node_id', 2,
'class_filter_type', 'include',
'class_filter_array', array( 'article' ),
'sort_by', array( 'published', false() ),
'limit', 5 ) )}A tree fetch over a large site is expensive: always filter by class and limit.
Counts for paging
list_count and tree_count take the same filter parameters (without sort_by, offset, limit):
{def $total = fetch( 'content', 'list_count', hash( 'parent_node_id', $node.node_id,
'class_filter_type', 'include',
'class_filter_array', array( 'article' ) ) )}Examples
The latest three news on the front page:
def $news_folder = fetch( 'content', 'node', hash( 'remote_id', 'mytheme-news-folder' ) )
if $news_folder
{def $latest = fetch( 'content', 'list', hash( 'parent_node_id', $news_folder.node_id,
'sort_by', array( 'published', false() ),
'limit', 3 ) )}
foreach $latest as $itemnode_view_gui content_node=$item view='line'/foreach
undef $latest
/if
undef $news_folderRelated pages
- Fetch basics
- Fetch filters and sorting
- Pagination
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.