Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Twig embed vs extends

Started by Muut Archive 11 years ago · 6 replies · 1410 views
11 years ago

I just had a look into the blog skeleton which uses antimatter theme. I noticed that some template files uses "extends" and other do use "embed". For example item.html.twig uses:

{% embed 'partials/base.html.twig' %}

{% endembed %}

I changed it to:

{% extends 'partials/base.html.twig' %}

and couldn't see any difference. It works as before.

So could anyone tell me whats the difference between those two and when use to which?

11 years ago

I read this before and I get the basic Idea, but I still don't quite understand why embed is used on the item.html.twig :(

11 years ago

I probably was using something before that required embed and then removed it or refactored it. embed is similar to extends but lets do more such as multiple levels of block extending.

11 years ago

Mhh… all right! If I understood correctly I would use extends to include the content/skeleton of my main template base.html.twig into the child template blog.html.twig. If I need to include another child-template inside my blog.html.twig which has some blocks I would like to override then I have to use embed. Is this right? Or

11 years ago

Easiest way to think about it is to use extends until you run into a situation where you can't. Then you are probably going to need embed :)

11 years ago

Ah that's a good one! I'll keep that in mind Thank you. :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1349 9 years ago
Archive · by Muut Archive, 9 years ago
2 934 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2946 9 years ago
Archive · by Muut Archive, 9 years ago
3 1117 9 years ago