7

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

1
  • Be careful that _self is deprecated everywhere but used with the {% import %} tag.
    – Alain
    Oct 12, 2015 at 14:41

2 Answers 2

11

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.

6

I found it here:

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

Under Global Variables

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.