Ad
How Can I Add A Class, Id Or Attribute To A Twig Include?
I am working on a project that uses twig. Each page uses
{% extends "_layouts/_master" %}
Inside the _layouts/master there is a body tag
<body class="{% block bodyClass %}{% endblock %}">
Can I add a class to the body tag from a page that is using the include?
Ad
Answer
You can override parent block (defined in _layouts/_master
) in child template (the one that extends parent). In your child template add this:
{% extends "_layouts/_master" %}
{% block bodyClass %}css-body-class another-css-body-class{% endblock %}
You can also include content of parent block and append something to it:
{% extends "_layouts/_master" %}
{% block bodyClass %}{{parent()}} css-body-class another-css-body-class{% endblock %}
You can read more in twig documentation for extends.
Ad
source: stackoverflow.com
Related Questions
- → October CMS create a multi select Form field
- → How to update data attribute on Ajax complete
- → laravel blade templating error
- → should I choose reactjs+f7 or f7+vue.js?
- → How to dynamically add class to parent div of focused input field?
- → Setting the maxlength of text in an element that is displayed
- → Undefined Result for Variable with Javascript innerHTML function
- → Expanding search bar not expanding before search
- → Get the calling element with vue.js
- → Blade: how to include a section in one page but not in another
- → How to print/log reactjs rendered dom?
- → how to write react component to construct HTML DOM
- → How to add a timer in HTML5 and Javascript?
Ad