WARNING: This bundle is still under developement and is not considered stable.
A common demand in web developement is to give the user (client) a possibility to manage the content of his website - this is when a CMS comes in. But there are some parts of the site, that we need to keep intact, just to keep things working or ones that we want to hide from the user, to avoid confusion caused by their complexity.
One of the main goals of RogerCMS is to provide easy means to achieve that.
Using a CMS-defined template in a view file requires only two lines of code
-
In the return part of your controller, call the "theodo_roger_cms.templating" service:
public function myAction() { /** * Some complicated stuff */ return $this->get('theodo_roger_cms.templating') ->renderResponse( 'MyBundle:myFolder:my.html.twig', $variables ); }
-
Call the template in your file, prefixing its name by 'layout:':
{# my.html.twig #} {% extends 'layout:my-layout' %}
Having the example controller action:
public function productListAction()
{
$products = $this->getDoctrine()
->getEntityManager()
->getRepository('MyBundle\Entity\Product')
->findAll();
return $this->render(
'MyBundle:Company:products_list.html.twig',
array('products' => $products)
);
}
And an example template:
{% extends 'MyBundle::layout.html.twig %}
{% block lead %}
{% endblock %}
{% block products %}
{# products display logic #}
{% endblock %}
How to give the client a possibility to change the lead text, without altering the products display?
-
Create a page in the CMS, giving it "products-list" as a slug.
-
Create a tab for block called "lead", and make your cms page extend your local template. This feature is part of, soon-to-be-ready, expert mode, the current solution requires altering manually the page row in database. To avoid that, you can register your template as standard CMS template, and move it to a file as soon as it's possible.
-
Use the "theodo_roger_cms.templating" and "theodo_roger_cms.content_repository" services in your controller to display your page:
public function productListAction() { $products = $this->getDoctrine() ->getEntityManager() ->getRepository('MyBundle\Entity\Product') ->findAll(); $cmsPage = $this->get('theodo_roger_cms.content_repository') ->getPageBySlug('products-list'); $variables = array( 'products' => $products ); return $this->get('theodo_roger_cms.templating')->renderResponse( 'page:'.$cmsPage->getName(), array( 'page' => $cmsPage ) + $variables ); }
-
And from now, your "lead" block can be easily modified from the CMS backend.