A
A
Alexander2015-03-13 21:46:04
MODX
Alexander, 2015-03-13 21:46:04

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;
}

ps I do all this nonsense in order to be able to display all child pages on the main page in the form of blocks using different styles. Maybe there is a better solution? Those. you need to create a page so that it is not a resource, but a block in the parent page, and this block can have one of the available styles applied.
p.p.s. Of course, I understand that it is possible to replace all placeholders with values ​​from $pageObject using str_replace(), but somehow it will not look very good =)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
7
7rows, 2015-03-16
@7rows

Why don't you like Doclister or MultiTV??
PS I don't understand your problem =(

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question