Ibexa DXP Discussions

Community discussion forum for developers working with Ibexa DXP

Templating with Netgen Site API

Hi,

I’ve started developping twig templates and controllers with Netgen Site API on ezPlatform v2.0

As a starter I’m reading docs on https://github.com/netgen/ezplatform-site-api and following the video webinar https://www.youtube.com/watch?v=GafiFeTGQ9I&t=1595s

I would like to find some more examples, does anyone know where I could find some kind of use cases, etc… ?

Thank you

All available docs are already in the repo at https://github.com/netgen/ezplatform-site-api/blob/master/USAGE.md

Is there a specific topic you need help with?

1 Like

A kind of “starter kit” for beginner with Symfony + Twig + ezplatform.yml , like me:
for instance, a simple example if I need to write a twig template + controller for a view full object with a simple action (like displaying the subitems): the yml mecanism yml + controller for executing this action.
As soon as I have understood this mecanism, I think I’ll be able to understand the other examples provided in the github/netgen/ezplatform-site-api docs.

I don’t have anything handy right now, but I think my colleague intends to write up a quick start tutorial pretty soon. I can give you the example of a page from one of our demo sites.

First you need to activate the full view route override:

netgen_ez_platform_site_api:
    system:
        frontend_group:
            override_url_alias_view_action: true

Then you define the override rule for the template:

ezpublish:
    system:
        frontend_group:
            ngcontent_view:
                full:
                    article:
                        template: "AppBundle:content/full:article.html.twig"
                        controller: "AppBundle:Demo:viewArticle"
                        match:
                            Identifier\ContentType: article

The controller:

<?php

namespace AppBundle\Controller;

use Netgen\Bundle\EzPlatformSiteApiBundle\Controller\Controller;
use Netgen\Bundle\EzPlatformSiteApiBundle\View\ContentView;

class DemoController extends Controller
{
    /**
     * @param \Netgen\Bundle\EzPlatformSiteApiBundle\View\ContentView $view
     *
     * @return \Netgen\Bundle\EzPlatformSiteApiBundle\View\ContentView
     */
    public function viewArticleAction(ContentView $view)
    {
        $content = $view->getSiteContent();
        $location = $view->getSiteLocation();

        $filterService = $this-getSite()->getFilterService();

        // Custom logic here
        ...

        $view->addParameters(
            array(
                // Adding a variable to the view
                'items' => $items,
            )
        );

        return $view;
    }
}

Finally, create the template:

{# AppBundle:content/full:article.html.twig #}

{% extends 'AppBundle::pagelayout.html.twig' %}

{% block content %}
    {# In here, you have access to content and location Site API objects #}
{% endblock %}
2 Likes

Great !
This is exactly that kind of example (and especially the Controller) I needed to start.
It’s very comfortable to keep on developping & learning.

Let me know if you’re stuck :slight_smile:

I think we should add this to the repo as a HOW_TO_START.md, @MarioBlazek agrees.

@storton here is a more detailed getting started guide: https://github.com/netgen/ezplatform-site-api/blob/master/GETTING_STARTED.md

1 Like

Thanks a lot Netgen guys ! :wink:

One more fresh improvement - PagerFanta traits:

Latest info about Site API: https://www.netgenlabs.com/Blog/Site-API-for-eZ-Platform-docs-workshop-video-and-more

Collecting feedback: Site API - collecting feedback