Search code examples
expressionenginesafecracker

Related entries in a Safecracker form?


I'm trying to create a Safecracker form in ExpressionEngine to create a recipe. I have a recipe channel, which can have many ingredients from an ingredients channel (using the multi-relationship add-on from devot:ee). However, I'm having trouble listing the ingredients within my form. This is my mark-up:

{exp:safecracker channel='recipes' datepicker='no' id='add-recipe-form' include_jquery='no' return='recipes/view/ENTRY_ID' safecracker_head='no'}
    {related_entries id='ingredients'}
        {title}
    {/related_entries}
{/exp:safecracker}

The problem is, the actual EE tags are just getting output on my web page.

I figure I'm doing something fundamentally wrong, so could someone point me in the right direction? Thanks.


Solution

  • This is called "variable collision" - you're nesting entries which use the same variable/tag names as those used by the parent tag (in this case, {title}), and due to how EE's parse order works, the parent tag is winning every time.

    The solution is to put your above code into another template, and embed that template within your Safecracker form. Embeds are run at the very end of template processing, after all of the other EE tags are parsed, so you won't run into the same collision.