Sulu Symfony CMS : play with child's of node
Sulu give you the ability to create page content (node of type content) , and this page can contain child's page as you know CMS system need this technique for more flexibility .
First you can get the instance of your parent document let's say you have blog as the top parent document of other child's , ok for getting the path of you document you can extract from table phpcr_nodes in your db from column path ok my path is '/cmf/ibnab/contents/blog' (sulu take the name of this path document from title of your page content)
Ok now getting the service document_manager and find your document :
$documentManager = $this->get('sulu_documentmanager.document_manager'); $document = $documentManager->find('/cmf/ibnab/contents/'.$toptag ,$languageCode);
And now get service node_repository and use for getting the childs document (or nodes) :
$webspaceKey = 'ibnab'; $languageCode = 'en'; $repository = $this->get('sulu_content.node_repository'); $_currentblog = $repository->getNodes( $document->getUuid(), $webspaceKey, $languageCode );
Yes pass to twig :
$response = $this->renderStructure( $structure, ['page' => $_currentblog], $preview, $partial ); return $response;
And inside twig :
{% for child in page._embedded.nodes %} <li class="2"> <a href="{{ sulu_content_path((child .url)) }}">{{ child.title }}</a></li> {% endfor %} {% endif %}
Ok that is all .
Comments