Symfony2 security functions in Twig? How to check the user's role? - symfony

I have Symfony 2.0.9 standard edition installed with JMSSecurityBundle. Just wondering what functions are available to me in a Twig template to deal with users?
Specifically I want check to see if a user has the role ROLE_ADMIN.
Any help?
Thanks

{% if is_granted('ROLE_ADMIN') %} ... {% endif %}

Related

Polylang on Wordpress site built with Timber won't switch author bios

I have a Wordpress site built on Timber/twig that uses Polylang to show different posts based on the language.
The posts show fine in the different languages, but the author bios that are loaded with:
{{ author.description }}
or
{{ post.author.description }}
only show the default language bio even when other language bios are entered into that author/user page.
Has anyone seen this issue before?
The Polylang documentation says nothing about how to properly add in a bio other than literally saying to enter the different bios into the user page....

Integrating Forum into Django CMS

I want to integrate my existing app, say a forum into Django CMS.
The problem is I don't want users to have any Django CMS capabilites.
They should not be able to see the edit bar or anything Django CMS related.
I only want them to have access to other Django apps. No Django CMS specific things like pages, plugins etc.
Is it possible? How?
The simplest way would be to restrict the CMS toolbar to super users;
{% if request.user.is_authenticated and request.user.is_superuser %}
{% cms_toolbar %}
{% endif %}
The toolbar is also part of the request object so in your app views you could disable it by doing something like request.toolbar.show_toolbar = False (docs)

Symfony2 Sylius e-commerce check for routes

I am working with Sylius e-commerce (Symfony 2), and I want to know is it possible to check is my route accessed.
For example if I have 3 kind of routes :
../aboutus.. /home.. /contact
and how I could check if my /home is accessed so I can do some actions about that.
Thanks,
Cheers
I think that I've found solution to this, in a twig.template you can do this:
{{ app.request.get('_route') }}
that returns path of accessed route

sonataadmin as both frontend and backend for symfony 2 project

I used sonataadmin and really like some features, like creating an entity and its related entity in the same page. I want to use it for frontend user also. Is it possable to use sonamaadmin for both backend and frontend users? Or is there another bundle allowing me to create an entity and its related entity in the same page?
Those are just form types, provided by the SonataAdminBundle. You can use them in any form.
You probably looking for the sonata_type_model or sonata_type_collection. See the documentation for more information.
Of course you can use Sonata Admin in both, although will be like only having a backend and made the correct security configuration for two kind of users. About entity and its related entities in the same page, that has nothing to do with Sonata, this can be achieved with symfony simple and embed forms.

Symfony2 FOSUserBundle Global template

How can I force FOSUserBundle to render all its pages as a part of my global template.
i tried to insert layout.html.twig from FOS UB to {% block login %} in my ::base.html.twig file which is above my default content in {% block body %}. when user enters page and logs in its ok but if he make for example password error he see only login form not the whole page.
I have also overriden layout of FOS UB to extend ::base.html.twig but how to make next steps?
Check Override template section of the doc.
Edit
Login action redirection is done by Symfony's internal Authentication/firewall system. If you enter wrong password the Symfony automatically redirects to login action you defined in firewall. For more info you can check Security section of the book. In this case you have to modify login.html.twig of FOSUserBundle to use your base template.

Resources