/   /   /  Sulu Symfony CMS : play with child's of node

Note:

For more extensions and themes visit our store

Sulu Symfony CMS : play with child's of node


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 :

  1.  
  2. $documentManager = $this->get('sulu_documentmanager.document_manager');
  3. $document = $documentManager->find('/cmf/ibnab/contents/'.$toptag ,$languageCode);
  4.  

And now get service node_repository and use for getting the childs document (or nodes) :

  1.  
  2. $webspaceKey = 'ibnab';
  3. $languageCode = 'en';
  4. $repository = $this->get('sulu_content.node_repository');
  5. $_currentblog = $repository->getNodes(
  6. $document->getUuid(),
  7. $webspaceKey,
  8. $languageCode
  9. );
  10.  

Yes pass to twig :

  1.  
  2.  $response = $this->renderStructure(
  3.       $structure,
  4.       ['page' => $_currentblog],
  5.       $preview,
  6.       $partial
  7.  );
  8.   return $response;
  9.  

And inside twig :

  1.  
  2.  {% if page._embedded.nodes is defined %}
  3. {% for child in page._embedded.nodes %}
  4.  <li class="2">
  5. <a href="{{ sulu_content_path((child .url)) }}">{{ child.title }}</a></li>
  6. {% endfor %}
  7. {% endif %}
  8.  

Ok that is all .

Comments

make your store more efficient

Solving problems. With open source technology. Professional results. That’s what makes Ibnab your best choice

IBNAB is a company made of a group of professionals whose work is providing secure open source solutions. Our company strives for reaching magnificent results with each experience and provides professional open source solutions that cover every part of the business process.