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 !
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 want to display a plain django-cms menu. I override the default menu/menu.html template, as I want to display the page's title, alongside the page's menu title. This is for a content navigation, where the additional info of the title is useful.
The default is (in the <a></a>):
{{ child.get_menu_title }}.
What I want is
{{ child.get_menu_title }}<span>{{ child.the_page_title }}</span>
But, somehow, I cant display the title alongside the menu_title. If the field menu_title is set, it overrides the title attribute of the NavigationNode, and it is returned when calling get_menu_title (obviously). Also, the title is not in the attr (NavigationNode attr).
I just ended using
{% load cms_tags %} {% page_attribute 'title' child.id %}
This might not be ideal concerning performance, but works very well. Open but for better solutions!
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 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.
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