Russ K. | 07/09/2021 Categories: Web Development | ExpressionEngine |
This entry has been viewed 244 times.
Partials vs Embed in ExpressionEngine
In ExpressionEngine, there are two elements – template partials and embeds – that act much like a traditional php "include". Although seemingly the same on the surface there are a couple important differences between them that make one a better choice over the other in different cases.
Template partials are rendered INSIDE the page they are called into.
Template partials are reusable snippets of code. The main thing to remember about a partial is that any code inside of it executes AFTER being called into the page. What this means is that if your partial contains EE code - for example a Channel Entries tag - you cannot place it into a page INSIDE of another Channel entries tag. If you need to structure you page this way, then you will want to use an embed.
Embeds are are rendered OUTSIDE the page they are called into, and then the rendered output inserted into the page.
An embed is a reusable snippet of code in which the contents of the embed are executed outside of the page. So in this case you can place an embed inside of a Channel entries loop.