In sections where the menu hierarchy is deeper than level 0 > level 1, I want to show a sub-menu (pages under level 1) in another part of the page. What I came up with is a little convoluted and I’d appreciate any input on the performance implications and how to benchmark these things. Any suggestion along the lines of "do X, because it is easier, faster, better" are also welcome.
I have a snippet called getDepth that looks like this:
$parent = $modx->resource->get('parent');
$rents = array ();
$values = array();
$level = 0;
$next;
$values[$level]['pid'] = $modx->resource->get('id');
while ($parent > 0) {
$level++;
$values[$level]['pid'] = $parent;
$next = $modx->getObject('modResource', $parent);
$parent = $next->get('parent');
}
$depth = $level + 1;
while ($depth--) {
$i = $level - $depth;
$rents[$depth]['pid'] = $values[$i]['pid'];
};
$output = array ();
if (isset($l)) $output['level'] = $level;
if (isset($p)) $output['start'] = $rents[$p]['pid'];
$modx->setPlaceholders($output,'d.');
In my template I have:
[[!getDepth? &l=`1` & p=`1`]]
[[!$tertiary]]
on another note, I’d prefer to cache as much as heavily as possible once development is done, are cached snippets and chunks at the template level cached for the entire template or per resource?
and in the tertiary chunk I have:
[[!If? &subject=`[[+d.level]]` &operator=`>` &operand=`0` &then=`<div id="tertiary">
[[!Wayfinder? &startId=`[[+d.start]]` &parentRowTpl=`navOuter`]]
</div>`]]
There is a top level navigation generated by wayfinder with &level=`2`
So navigation exists like this:
PRODUCTS
--Product One
--Product Two
--Product Category
and there are breadcrumbs like this:
Home > Products > Category > A Product
Which made me wonder, since I am using the breadcrumbs snippet, if it couldn’t be modified to set placeholders like d.level and d.start
... but my main question is, how bad/inefficient is what I’ve come up with here?
Thank you!