Sulu cms framework is an open-source content management platform based on the Symfony PHP framework. Use it as a CMS to develop and manage enterprise multi-sites or as a development environment to create reliable and high-performant web-apps.
The official doc is here
That is our first tutorial in this cms , we used and observe that is easy and practice but need more large community .
Ok this tutorial cover how getting collection of nodes based on tag name .
- Some parameters used inside our code :
$dataSource = null; $includeSubFolders = null; $languageCode = 'en'; $tagOperator = 'or'; $sortBy = 'date'; $sortMethod = 'asc'; $exclude = null; $webspaceKey = 'ibnab'; $limitResult = 1; $tagNames = 'sulu'; $resolvedTags = [];
- Get service tag manager :
$tagManager = $this->get('sulu_tag.tag_manager'); foreach ($tags as $tag) { $resolvedTag = $tagManager->findByName($tag); if ($resolvedTag) { $resolvedTags[] = $resolvedTag->getId(); } } }
- Some code about sorted columns :
$sortColumns = []; foreach ($columns as $column) { if ($column) { $sortColumns[] = $column; } } }
- Create global configuration used in our repository selection :
$filterConfig = [ 'dataSource' => $dataSource, 'includeSubFolders' => $includeSubFolders, 'limitResult' => $limitResult, 'tags' => $resolvedTags, 'tag' => $tagOperator, 'sortBy' => $sortColumns, 'sortMethod' => $sortMethod, ];
- New get service and call the method getFilteredNodes :
/** @var NodeRepository $repository */ $repository = $this->get('sulu_content.node_repository'); $contents = $repository->getFilteredNodes( $filterConfig, $languageCode, $webspaceKey, true, true, $exclude !== null ? [$exclude] : [] );
- The collections nodes is inside :
$contents = $contents['_embedded']['nodes'];
- You can pass to twig :
$response = $this->renderStructure( $structure, ['contents' => $content], $preview, $partial ); return $response;
- Now dumping inside twig :
{{ dump(contents) }}
that is all
Comments