How can I add a class, id or attribute to a twig include?

DumbDevGirl42069

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?

Nima

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I select same attribute without using class or id?

From Dev

How can I use setAttribute on an input without an ID or class attribute?

From Dev

Can we add attribute(i.e. id/class) on any div which is inside the <script type="text/template" id="template"><script>

From Dev

How can I add an instance attribute in subclass?

From Dev

How can I add dynamically an attribute with VueJS?

From Dev

How can i add an custom attribute and assign it to an existing custom object class in sun ds

From Dev

How can I add a `/` to an attribute I'm binding data to?

From Dev

Can I add the Twig file type to Linux?

From Dev

How can I change the inline style text color of an element without the ability to add a class or id?

From Dev

Symfony twig how to add class to a form row

From Dev

How can I add a class in ember js

From Dev

How can I dynamically add a method to a class?

From Dev

How can I add PHP wordwrap to this class?

From Dev

How can I add class to the specific datepicker?

From Dev

How can I not add a class to a specific block?

From Dev

How can I add an id to a variable in this situation?

From Dev

How can I add custom php include() file in wordpress

From Dev

How can I add an include line to an XKB configuration file?

From Dev

How can I add a filter to my grep script to NOT include a string?

From Dev

Maven: How can I run/include a class in a jar with the failsafe plugin?

From Dev

MVC 6 How can I include a BaseRepository in my controller class

From Dev

How can I generically .Include properties of entities limited to a certain class?

From Dev

How can i create a UIView class that include labels and textfields in Swift?

From Dev

How can i include files to use class in other included files?

From Dev

How can I add a value that is stored in web.config to a class attribute in c#(from web config file not the resource file)

From Dev

Can I include PHP templates in a TWIG base template or vice versa?

From Dev

How to add class attribute to ModelForm

From Dev

How can I add a custom attribute to a <span> and read it in JavaScript?

From Dev

How can I add the 'required' attribute to input on change of textarea?

Related Related

  1. 1

    How can I select same attribute without using class or id?

  2. 2

    How can I use setAttribute on an input without an ID or class attribute?

  3. 3

    Can we add attribute(i.e. id/class) on any div which is inside the <script type="text/template" id="template"><script>

  4. 4

    How can I add an instance attribute in subclass?

  5. 5

    How can I add dynamically an attribute with VueJS?

  6. 6

    How can i add an custom attribute and assign it to an existing custom object class in sun ds

  7. 7

    How can I add a `/` to an attribute I'm binding data to?

  8. 8

    Can I add the Twig file type to Linux?

  9. 9

    How can I change the inline style text color of an element without the ability to add a class or id?

  10. 10

    Symfony twig how to add class to a form row

  11. 11

    How can I add a class in ember js

  12. 12

    How can I dynamically add a method to a class?

  13. 13

    How can I add PHP wordwrap to this class?

  14. 14

    How can I add class to the specific datepicker?

  15. 15

    How can I not add a class to a specific block?

  16. 16

    How can I add an id to a variable in this situation?

  17. 17

    How can I add custom php include() file in wordpress

  18. 18

    How can I add an include line to an XKB configuration file?

  19. 19

    How can I add a filter to my grep script to NOT include a string?

  20. 20

    Maven: How can I run/include a class in a jar with the failsafe plugin?

  21. 21

    MVC 6 How can I include a BaseRepository in my controller class

  22. 22

    How can I generically .Include properties of entities limited to a certain class?

  23. 23

    How can i create a UIView class that include labels and textfields in Swift?

  24. 24

    How can i include files to use class in other included files?

  25. 25

    How can I add a value that is stored in web.config to a class attribute in c#(from web config file not the resource file)

  26. 26

    Can I include PHP templates in a TWIG base template or vice versa?

  27. 27

    How to add class attribute to ModelForm

  28. 28

    How can I add a custom attribute to a <span> and read it in JavaScript?

  29. 29

    How can I add the 'required' attribute to input on change of textarea?

HotTag

Archive