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.
Related
hello I was wondering how to customize the form on symfony instead of having already a ready-made template (especially the bootstrap one).
Hello here is the solution to this problem :
To start, here is the place where you can change the theme of the forms to Symfony:
// project_name/config/packages/twig.yaml
twig :
...
form_themes: ['bootstrap_4_layout.html.twig']
if you want to see the default packages that are available you have to go to the following folder :
project_name/vendor/twig-bridge/Resources/views/Form
Now you can notice that twig file names match the style that you can add for your forms made with twig
so now if you really want to make your own style of form just create a twig file in that same folder 'project_name/vendor/twig-bridge/Resources/views/Form' and then replace that filename with 'bootstrap_4_layout.html.twig' in 'project_name/config/packages/twig.yaml'
I set up a Drupal page, which has two different content-types. One is "articles", one is "reviews".
In my theme folder, I set up two node templates for these content types. node.html.twig (standard template - articles), and node--reviews.html.twig.
When I add an article, node.html.twig is used, when I add a review, node--reviews.html.twig is used.
Now, it's possilbe to have different comments types too. I want to add the standard comment (comment.html.twig) for articles, and a custom comment type to reviews.
In Drupals theme naming documentation it's written, to name a template override like this: comment--node-type.html.twig. So I named my comment template comment--node-reviews.html.twig.
Is there anything else I have to do - apart from clearing the cache?
Because I simply cant get it to run.
Enable Twig Debugging, then you'll get template suggestions printed as HTML comments directly into the markup.
I did that and got the following output:
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'comment__field_my_comment_field__article' -->
<!-- FILE NAME SUGGESTIONS:
* comment--field-my-comment-field--article.html.twig
* comment--field-my-comment-field.html.twig
x comment.html.twig
-->
<!-- BEGIN OUTPUT from 'core/themes/classy/templates/content/comment.html.twig' -->
So, the templates are supposed to be named like the following pattern:
comment--field-name-of-the-comment-field-in-the-content-type--content-type.html.twig
comment--field-name-of-the-comment-field-in-the-content-type.html.twig
I created a basic page with a NID of 176. My basic page content type contains a field called field_banner_image.
In my templates directory I created a file called page--node--176.html.twig and the template works.
I saw a few threads where you can access the node content via {{ content.field_name }}, however, my content appears to NULL every time.
I managed to output the URL of my image field via:
{{ file_url(node.field_banner_image.entity.uri.value) }}
I feel like there has to be an easier/better way of doing this. Any suggestions? Why is content null in my twig templates?
If your template is named page--node--176.html.twig, it is actually a page template overriding the base page template page.html.twig, so you will have access to all page variables but not those in your node.
Although your node type is called "page", it is still a node, and the template for it would be node--176.html.twig which overrides node.html.twig.
In your node--***.html.twig you will have access to the content variable. Let me know if you need help.
I'm trying to override the FOSUserBundle Templates as show here:
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_templates.md
I used the second method, I created my own bundle and put the templates in
myBundle/Resources/Views/Security/login.html.twig
and
myBundle/Resources/Views/Registration/register.html.twig.
both templates start with:
{% extends "::nologbase.html.twig" %}
where nologbase.html.twig is defined in app/Resourcer/views.
well, the first one (login) is correctly displayed but the second one (register) shows row html with no css.
I cleared the cache and I also tried to display only the extended template and compared the source code. it is exactly the same!
any idea?
thanks
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