ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Nested entries with nested templates

November 12, 2012 10:32am

Subscribe [1]
  • #1 / Nov 12, 2012 10:32am

    Sextans

    3 posts

    Hi,

    I’m sure this question does not deserve it’s own topic but I’ve failed to find a satisfying answer on the forums and Stack Overflow.

    I have three templates. I’ll try to be clear and simple about what I’m trying to do.

    Page

    {exp:channel:entries channel="page" dynamic="yes"}
        {if module_id}{embed="module/index" id="{module_id}"}{/if}
    {/exp:channel:entries}

    Module - Index

    {exp:channel:entries channel="module" dynamic="no" entry_id="{embed:id}" site="main_site"}
        {if module_type == "building"}
            {embed="module/building" id="{building_id}"}
        {/if}
        {!-- Other module type checking here… --}
    
        {!-- Note this following line --}
        {entry_id} - {embed:id}
    
    {/exp:channel:entries}

    Module - Building

    {exp:channel:entries channel="building" dynamic="no" entry_id="{embed:id}" site="main_site"}
        <h1>{title}</h1>
        {building_description}
    {/exp:channel:entries}

    So basically, in this setup you can attach “modules” to pages entries. In this particular case, I’m trying to look if any {module_id} was set on the page. If so, pass {module_id} to the main module template, which will get the module entry, compare the {module_type} and send {building_id} to a third template. Then the building information is fetched and displayed.

    In the module template, where I wrote a note, {entry_id} and {embed:id} does not match. {entry_id} equals the ID of the first page entry that was fetched dynamically. I assume this is happening because since it’s embedded templates and not snippets, it results in three nested {exp:channel:entries} tags. But then again, I can’t pass IDs to a snippet, can I?

    Also worth noting that I’m using MSM, and since I have 8 sites running on it, I wanted “modules” to be, well, modular and all reside under the “main site” for convenient maintenance.

    I hope someone can clarify this and/or correct me if I’m wrong.

  • #2 / Nov 14, 2012 12:06pm

    Dan Decker

    7338 posts

    Hi Sextans,

    Thanks for using the Official EllisLab Support Forums! Let me welcome you!

    In your second example -

    {!-- Note this following line --}
        {entry_id} - {embed:id}

    Those should be equal. The template parsing engine runs in full for each embed encountered. That means that variables like {entry_id} are scoped to the template that they are in, and not impacted by the parent template.

    My only suggestion for now is to prefix your embed variables so that “id” is different in each. So perhaps “p-id” and “mod-id”.

    Id this on a server we could log in to?

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases