0

In symfony cmf I like to create the following:

  • create a menu item called inside
  • create a container block called insideBlock
  • create multiple static contents, they should have as parent the container block

if a user clicks the menu inside, all items from static content should be displayed, which have as parent the insideBlock

I did not figure out how to do this. Of course I don't like to programs a function just for inside, since I would like other menus behaving the same way.

I am able to link a menu item to a static content and display this single content, but as soon as I select the container block, the menu item disappears...

EDIT

I have done this:

  • in my controller add a function like this:

    /**
    * @Route("/{_locale}/empfang", name="empfang_display_all")
    */
    public function empfangAction(Request $request)
    {
            $documentManager = $this->get('doctrine_phpcr')->getManager();
            $content = $documentManager->find(null, '/cms/content/empfangsgebiet');
    
            return $this->render('empfang/empfang.html.twig', [
                    'contents' => $content
            ]);
    }
    
  • added as route to the menu item empfang_display_all
  • static content set parent to the container
  • in the view

``{ % set index = 0 %}

{% for child in children %}
    {% if (child.name != "banner") and (isInstanceof(child, 'ContainerBlock') == false) %}
        <div class="{{ cycle(section1, index) }}">
            <div class="container">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="top-title">
                            <div class="row">
                                <div class="col-sm-10 col-sm-offset-1">
                                    {% if isInstanceof(child, 'DemoSeoContent') %}
                                        {{ child.body|raw }}
                                    {% else %}
                                        {{ sonata_block_render({ 'name': child.id }) }}
                                    {% endif %}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {% set index = index + 1 %}
    {% endif %}
{% endfor%}

I would now like to have the following line more dynamic

$content = $documentManager->find(null, '/cms/content/empfangsgebiet');

Preferable I would like to have it like this:

    /**
    * @Route("/{_locale}/empfang/{path}", name="empfang_display_all")
    */
    public function empfangAction(Request $request, $path)
    {
        $content = $documentManager->find(null, $path);
    }
schurtertom
  • 520
  • 1
  • 9
  • 19

1 Answers1

0

blocks are not routeable items, meaning they can't have their own url. i think the best way to do this is to use a normal page instead of the container block and configure the route of that page to use a special template. then you write a template that outputs the title of the page and maybe the text as a "lead", then loops over the children of the page and outputs those.

dbu
  • 1,497
  • 9
  • 8
  • hi dbu, I kind of done that in the meanwhile. I did create a container, add every content to this container, then add a menu item with custom route, create a function in my controller to display the children of this particular container... but when ever I add a new menu with children, I would have to create a custom function again, I would prefer having a general function to call... but from menu item, I did not figure out to add arguments to this route name... is there a possibility to do this? – schurtertom Nov 01 '16 at 02:45
  • you can use the routeParameters attribute in the menu attributes to tweak a route. – dbu Nov 02 '16 at 14:26
  • but i recommend to create a "container" document that is a sort of "page" so that can have its own route. then you just create such a container page, define the url and the custom template on the url, and add your blocks to it, and create a menu item pointing to that container page. – dbu Nov 02 '16 at 14:28