I try to make a web site with Symfony. So I installed SonataAdminBundle and SonataMediaBundle.
And I have a question about Sonata media.
I created a gallery with a lots of image media in it and I don't know how I can access it from my Controller.
How can I get my media (image) contained in my gallery for show them in my template?
thx for help !
EDIT:
I solved my problem !
So in my template I do:
{% for img in MyEntity.gallery.galleryHasMedias %}
<img src={% path img.media, 'reference'%}>
{% endfor %}
Usually Gallery or Media entity are related to other entities and we retrieve them from their relation.
e.g. from owner of a gallery or related medias to a product. after fetching pass media object(image in this case) to template(twig or php) and use sonata media helpers to display them.
Related
I'm new to D8. I want to customise the theme of a view. I have already created a block view and assigned into the sidebar of bartik's theme (default provided). See the below screen shot.
Now, I've made the twig debug as true and saw the theming guide for the view files:
<!-- FILE NAME SUGGESTIONS:
* block--views-block--articles-block-1.html.twig
* block--views-block--articles-block-1.html.twig
* block--views-block.html.twig
* block--views.html.twig
x block.html.twig
-->
Now, I have created a file named "block--views-block--articles-block-1.html.twig" within the path: "/themes/bartik/templates/views/" and wrote something like:
Hello
{% for row in rows %}
test
{% endfor %}
After clearing cache, I see there is no change in the view theme and it renders as default.
What did I missed?
You are creating block template that contains block title and content, not a views template.
The view template name should start by "views--".
#niladri, You have chosen format to unformmated.I will suggest to create template in views directory in your theme. Views-view-unformatted--[view machine name]--[view display name].html.twig
Clear cache after this via drush or Drupal
admin/config/development/performance.
I have Entity Product with productImages. ManyToOne relationship.
I want to override product images twig. To do it, I created easy_admin folder under view and inside ProductImage folder, then edit and new twigs for test.
It is not overriding at all. Product is overridden easily is this way, but ProductImage is not.
Don't you think in theory it should work like this?
If not, please give me some clue how to override, change collection type twig.
I want to have nice bootstrap table instead current one.
Thanks
If anyone is curious how to override collection type:
in config.yml add:
easy_admin:
design:
form_theme: '/custom_form_layout.html.twig'
Then in custom_form_layout.html.twig write:
{% extends 'EasyAdminBundle:form:bootstrap_3_horizontal_layout.html.twig' %}
Or extend your base form whatever it is.
after that override block
{% block collection_row %}<div>I Love Symfony! (or just use parent())</div>{% endblock collection_row %}
I would like to know if that's possible to get an image with {% path %} or {% media %} in a twig template from sonata, without crop/resize ? It seems that it's required to specify a format, but I would like to keep the original size in some case.
I have the idea to make a resizer that does nothing for this problem, but is it possible to specify a resizer by context and not a resizer for a provider in all contexts please ? Because I need to use a resizer in some case, but not in all.
If you want to display your uploaded image without resize / crop in twig you can do :
{% media media, 'reference' %}
More details in the documentation on how to use the twig helpers.
I want to add a dynamic menu to the frontoffice of my site where can i easely add a child menu or a new panel menu from the page admin .
how can i do that using symfony
You should code that menu, it's a good training if you're new to symfony.
For a dynamic menu, I usually do :
a Menu entity
a MenuItem entity
a controller for each, with a CRUD.
an action in the MenuController do show the menu (as a HTML unordered list for example).
Then you can edit the ::base.html.twig in app/Resources/view and you add a block menu and render the MenuController :
{% block menu %}
{{ render(controller('AcmeBlogBundle:Menu:list')) }}
{% endblock %}
With knpmenubundle you can easily create a Menu with child.
First of all, look at https://github.com/KnpLabs/KnpMenuBundle and read http://symfony.com/doc/master/bundles/KnpMenuBundle/index.html
Secondly use Doctrine and make a relation OneToMany (or ManyToMany but it's not recommended).
Use KnpMenuBundle as Service
Good luck !
First I am new in Symfony2, I develop a project by using Symfony2 with SonataAdminBundle, everything is well but I don't know how to add a custom link in top menu without entity.
You need to override the standard_layout.html.twig by creating a custom admin bundle and place that file in exact the same folder structure. If you open up the original standard_layout.html.twig you can see that it has following block in it {% block top_bar_before_nav %} {% endblock %}. That's the one you want to put your own menu item in. Here is some more info about templating the SonataAdminBundle.
You can configure the config.yml
sonata_admin:
templates:
user_block: YOURBUNDLE:<optional Directory>:Twig-template
That's for sonata admin bundle :( dev-master. Kind of 2.2.x
The template is warpped by an ul-tag, so use li's:
<li>First User message</li>
A helpful console-command is
php app/console config:debug sonata_admin