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.

Context in embedded files

March 31, 2011 10:52am

Subscribe [3]
  • #1 / Mar 31, 2011 10:52am

    richardjlyon

    12 posts

    This works:

    <div class="module">            
    <h2>Useful documents</h2>
    <p>{exp:playa:children}<br />
    <a href="http://{publication_url}">{title}</a> {publication_description}<br />
    {/exp:playa:children}<br />
    </div><!--module-->

    This doesn’t:

    <div class="module">
    {embed="includes/_modRelatedDocuments"}
    </div><!--module-->

    where _modRelatedDocuments contains

    <h2>Useful documents</h2>
    <p>{exp:playa:children}<br />
    <a href="http://{publication_url}">{title}</a> {publication_description}<br />
    {/exp:playa:children}

    Is context not preserved in embedded code ? How do you encapsulate in ExpressionEngine ?

  • #2 / Mar 31, 2011 12:42pm

    Brett Gullan

    70 posts

    Context isn’t preserved with embedded templates in the sense you mean. Embedded templates are handled separately to the main template. Do a search for ExpressionEngine template parsing for more info on that.

    You CAN pass variables into templates using code like this:

    {embed="includes/_modRelatedDocuments" somevar="somevalue"}

    Then within your template you can use:

    {embed:somevar}

    This works for simple parameterization, but doesn’t help much when trying to pass in lots of values.

    For your example, I’d suggest something like the following in the calling template:

    <div class="module">
    {embed="includes/_modRelatedDocuments" entry_id="{entry_id}"}
    </div><!--module-->

    And:

    <h2>Useful documents</h2>
    <p>{exp:playa:children entry_id="{embed:entry_id}"}<br />
    <a href="http://{publication_url}">{title}</a> {publication_description}<br />
    {/exp:playa:children}

    ... in the embed. (I’m assuming your {exp:playa:children} call is actually wrapped in an entry, so the {entry_id} value will be available.)

    HTH

  • #3 / Mar 31, 2011 6:45pm

    Sue Crocker

    26054 posts

    Thanks for the assist, Brett.

    Richard, does that make sense? You would need to pass in the entry_id like Brett shows in his example. Does that make sense?

  • #4 / Apr 02, 2011 4:35am

    richardjlyon

    12 posts

    Brett / Sue - thanks both, I’ll try this.

  • #5 / Apr 05, 2011 8:08am

    Sue Crocker

    26054 posts

    Sounds good..  If you run into any more problems feel free to start a new thread.

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

ExpressionEngine News!

#eecms, #events, #releases