if I use {embed="store/something"} and use {field:photo} inside something it doesn't appear but if I goto something directly the {field:photo} is visible and works fine. Is this a bug??? EE6
1 Answer
When you open one within a template EE generates a whole new template instance for an embed: the content of the embed are not affected directly by the conditions in the template that called it. This is one of (possibly the only) the features of embeds that give reason for using one. The details of what is going on are explained well in the documentation.
So in your case, since the embed 'starts again' it won't know what is being referred to by any variable field unless you run a new channel:entries tag within the embed.
This lack of awareness of context is unhelpful - usually you want an embed to be responsive to the circumstances where the embed is called - and to address this embeds can pass variables from the context to the embed - simply add parameters with the name of the variables you want to use within your embed and then reference these parameters using the {embed:variable_name}
construct within your embedded templated.
So in your case you could modify your embed tag to read:
{embed="store/something" photo="{field:photo}"}
and in your embed template access the {field:photo}
value using the variable {embed:photo}
.
Alternatively, if you don't need or want the separate template instance - for example if you are simply looking to reuse a common code block in several templates - you might be better to consider either putting your embed code into a template partial, or possibly refactoring your template to let you make use of layout variables.
HTH
-
1