[SonataPageBundle] Example to create a dynamic page

1,053 views
Skip to first unread message

Cassiano Tartari

unread,
Nov 26, 2013, 11:13:35 AM11/26/13
to sonata-users
Hello!

   I am here trying to figure out how to create a dynamic page in SonataPageBundle without to much work. Looking in the code how is generate the news pages I thinking to complex. I was just wondering to create a dynamic realty page to a real state website. Just like http://localhost/realty/{code}.

  Does anyone have a simple example of this?

Thanks.

Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code

Thomas Rabaix

unread,
Nov 26, 2013, 11:31:08 AM11/26/13
to sonata...@googlegroups.com
  • Just create a route like realty_show
  • create the related controller
  • create the related template (with no main html header, only the body)
  • run the task sonata:page:update-core-route --site=all

At this point you should have a page name realty_show in the sonata backend, you can assign a template to this page .

That's it. ..



--
You received this message because you are subscribed to the Google Groups "sonata-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonata-users...@googlegroups.com.
To post to this group, send email to sonata...@googlegroups.com.
Visit this group at http://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/groups/opt_out.



--
Thomas Rabaix
http://rabaix.net | http://sonata-project.org

Cassiano Tartari

unread,
Nov 26, 2013, 1:24:39 PM11/26/13
to sonata-users
Thanks!

I was almost getting, but just when I start I didn't get how the render from controller would write inside a the template. I was creating a new complex template for the real state and now I found that this template should have the content render:

                  {% if content is defined %}
                {{ content|raw }}
            {% else %}
                {% set content = block('content') %}
                {% if content|length > 0 %}
                    {{ content|raw }}
                {% elseif page is defined %}
                    {{ sonata_page_render_container('content', page) }}
                {% endif %}
            {% endif %}


So just to have here an example:


  • Just create a route like realty_show

#routing.yml

company_view_entity:
    path: /entity/{code}
    defaults:
        _controller: CompanyMyBundle:Entity:view

  • create the related controller

    /**
     * @throws NotFoundHttpException
     *
     * @param $permalink
     *
     * @return Response
     */
    public function viewAction($code)
    {
        $
entity = $this->getDoctrine()->getRepository('CompanyMyBundle:Entity')->find($code);

        if (!$imovel) {
            throw new NotFoundHttpException('Not found');
        }

        //logic


        return $this->render('CompanyMyBundle:Entity:view.html.twig', array(
            'entity' => $
entity        ));
    }

  • create the related template (with no main html header, only the body)

{# Company/MyBundle/Resources/views/Entity/view.html.twig #}

{{ dump(entity) }}

    • run the task sonata:page:update-core-route --site=all
    • app/console sonata:page:create-snapshots --site=all



    Cassiano Valle Tartari
    MSc. Computer Engineer

    Tel: +55.48.84474818
    Email: fal...@cassianotartari.eng.br
    Site: http://www.cassianotartari.eng.br

    QR Code


    Thomas Rabaix

    unread,
    Nov 26, 2013, 1:36:18 PM11/26/13
    to sonata...@googlegroups.com

    You can now write a cookbook entry for the page bundle ...

    --
    Thomas Rabaix
    http://rabaix.net - http://sonata-project.org

    Cassiano Tartari

    unread,
    Nov 26, 2013, 1:56:58 PM11/26/13
    to sonata-users
    I don't have idea how to do it... And not so much time for it, If you could give me a cookbook to "write a cookbook" it could be possible, write something simple and directly like I did in the thread will be a pleasure.

    Cassiano Valle Tartari
    MSc. Computer Engineer

    Tel: +55.48.84474818
    Email: fal...@cassianotartari.eng.br
    Site: http://www.cassianotartari.eng.br

    QR Code


    mario7...@gmail.com

    unread,
    May 4, 2015, 2:01:44 PM5/4/15
    to sonata...@googlegroups.com
    When i create a hybrid or dynamic page in my bundle, it always says "Twig_Error_Loader: Unable to find template ""."

    When i create a hybrid page in SonataDemoBundle it works just fine.

    My Controller:

    class ShopController extends Controller
    {
    /**
    * @param \Symfony\Component\HttpFoundation\Request $request
    *
    * @return \Symfony\Component\HttpFoundation\Response
    */
    public function viewAction (Request $request) {

    $this->render('SonataTestBundle:Shop:view.html.twig');
    }
    }

    My View:

    {% extends '::empty.html.twig' %}

    {% block page %}
    <h2>foo</h2>
    {% endblock %}

    My Route :

    <route id="sonata_test_view" pattern="/bestellen">
    <default key="_controller">SonataTestBundle:Shop:view</default>
    </route
    >

    then i run

    • app/console sonata:page:update-core-route --site=all
    app/console sonata:page:create-snapshots --site=all

    For some reason an empty Templatename is being passed.

    What am i missing?

    Any help is appreciated. Thank in advance.

    Thomas Rabaix

    unread,
    May 5, 2015, 9:20:14 AM5/5/15
    to sonata...@googlegroups.com
    if the page is configured in the Page Admin ? if decorated is set to true, then you must define a valid template.

    For more options, visit https://groups.google.com/d/optout.



    --
    Reply all
    Reply to author
    Forward
    0 new messages