0

I have some content in my layout that are not supposed to be displayed in some pages.

E.g.: When a user is registering for the site my default frontpage sidebar should not be displayed:

<!DOCTYPE html>
<html>
    <head>
        {% block head %}
            <link rel="stylesheet" href="style.css" />
            <title>{% block title %}{% endblock %} - My Webpage</title>
        {% endblock %}
    </head>
    <body>
        <div id="content">
           <div id="sidebar">
               {% block sidebar %}
                   {% render "/layout/sidebar" %}
               {% endblock %}
               {% block content %}{% endblock %}
           </div>

        </div>
        <div id="footer">
            {% block footer %}
                &copy; Copyright 2011 by <a href="http://domain.invalid/">you</a>.
            {% endblock %}
        </div>
    </body>
</html>

In the above code:

 {% block sidebar %}

should display some advertising instead!

So:

Something like:

{% if SOMEVIEW == TRUE %}
    {% block sidebar %}
{% else %}
    {% block advertising %}
{% endif %}

What expression could I use in my IF to accomplish that job?

Thanks in advance

Gilberto Albino
  • 2,572
  • 8
  • 38
  • 50

2 Answers2

1

You can look at How to check if an user is logged in Symfony2 inside a controller?

and http://symfony.com/doc/current/book/security.html#access-control-in-templates

In the view you can use {{ is_granted('IS_AUTHENTICATED_FULLY') }} to check if a user is logged in.

Hope it's helpful.

Best regard.

Community
  • 1
  • 1
Benjamin Lazarecki
  • 2,950
  • 1
  • 20
  • 27
0

I came accross to the solution here http://symfony.com/doc/current/cmf/bundles/core.html#twig:

app.request.attributes.get('_template').get('name')

will return the route name so that I can handle it inside my twig files.

Gilberto Albino
  • 2,572
  • 8
  • 38
  • 50