Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twig "_self" variable

Tags:

twig

symfony

Where is documented the existence of this keyword? (I guess it is a constant, rather than an object, right?).

Anyway, I'd like to know where it is documented, to see if there are other keywords that I don't know about.

Thanks

like image 200
JorgeeFG Avatar asked Jan 13 '14 19:01

JorgeeFG


People also ask

What are macros in Twig?

From the official Twig documentation: "Macros are comparable with functions in regular programming languages. They are useful to put often used HTML idioms into reusable elements to not repeat yourself."

How can we use spaceless in Twig template?

As of Twig 2.7, use the spaceless filter instead. This tag is not meant to "optimize" the size of the generated HTML content but merely to avoid extra whitespace between HTML tags to avoid browser rendering quirks under some circumstances.

How do you write a Twig?

To start writing Twig code in your HTML, there are only two different syntaxes: {{ }} The "say something" syntax. {% %} The "do something" syntax.


2 Answers

This doesn't really answer the question, but I think it's important to mention it. The _self itself is not really deprecated nor removed, but its usage is!

If you look for deprecated features in Twig 2.*, you'll find there are none. So, you may think falsely that you're safe, or scratch your head (like I did) in finding why did it stop working in v2.0.

But actually, in Twig v1, _self was an object, with which you could do _self.templateName, or call Twig macros with it. Its usage as object was deprecated but it worked.

In Twig v2, _self is no more an object but a string, which actually holds the templates name (the previous value of _self.templateName).

So, if you used it in Twig v1 as an object - your code will fail in Twig v2. Anyway, it seems like a bit messy resolution of the _self issue.

like image 154
userfuser Avatar answered Dec 06 '22 02:12

userfuser


I found it here:

http://twig.sensiolabs.org/doc/templates.html

Under Global Variables

like image 42
JorgeeFG Avatar answered Dec 06 '22 03:12

JorgeeFG