Intro Flashcards
Twig Syntax: Say, Do & Comment
{{ say something }}
{% do something %}
{# comment on something#}
Say-do-comment
How would you print the value of a variable named title?
{{ title }}
How would you print the spotlight region of a page in Drupal 8.x?
{{ page.spotlight }}
Twig do something?
{% do something %}
Output “footer first” region with HTML
{% if page.footer_first %} <div class="site-footer\_\_bottom"> {{ page.footer_first }} </div> {% endif %}
Inheritance in Twig: define extends and block
“extends” keyword allow you to dress a template with another template’s markup
“block” defines an area that may be customized; another template’s code may be inserted in this block area
Inheritance in Twig: define extends
extend - dress - other template’s markup
Inheritance in Twig: define block
block - another templates code inserted here
When template uses extends, what happens?
When a template uses extends, all markup is surrounded by block tags to define the custom markup
To override 3 things:
Locate template you want to override
Make a copy
Place in your custom theme/templates folder
Overrides can be what 2 things?
General - override page.html.twig everywhere
Specific - override page.html.twig on node 22
Some security enhancements in Twig?
- Twig introduces autoescaping and sanitizes all HTML to prevent XSRF attacks
- PHP WILL NOT be executed in a Twig file and will display as plain text
XSRF stands for?
Cross Site Request Forgeries - big problem in D7
With Twig, what no longer goes in templates?
PHP. No PHP in templates
True/False? The render keyword is not used in Twig
True