Answer the question
In order to leave comments, you need to log in
How to get a finished page from a snippet in ModX Revo?
Hello. Can you help me get a page with a template applied to it (not a chunk!) from the snippet?
The situation is this: there is a template (Template), which does not contain the entire page, but a piece of code - a small block without headings, etc. I'll call it "sub-template" :)
I create a resource (page) and select this sub-template as a template. This resource does not need to be accessed from the address bar.
In the main template (parent page), I insert a snippet in a specific place that should render this page (child) in finished form with the subtemplate applied (which is specified in the resource editor, not in the snippet parameters!). But the trouble is that placeholders are replaced by the values of the parent page. How to change placeholders to children values?
Snippet code:
// узнаем id страницы вызвавшей сниппет
$parentPageId = $modx->resource->get('id');
// определяем id-ы всех дочерних ресурсов и перебериаем их
$childrenPageIds = $modx->getChildIds($parentPageId);
foreach($childrenPageIds as $index => $childrenPageId)
{
// получаем ресурс
$pageObject = $modx->getObject('modResource', array(
'published' => 1,
'id' => $childrenPageId
));
// получаем шаблон ресурса
$templateObject = $modx->getObject('modTemplate', $pageObject->template);
// выводим
return $templateObject->content;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question