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.

{if} conditional embedding

April 15, 2011 10:55am

Subscribe [2]
  • #1 / Apr 15, 2011 10:55am

    sheferd

    31 posts

    Hi,
    I’m trying to embed a template into a page only if a certain element is present.
    This is what I am using:
    {if image-2}{embed="globals/_js-slide"}{/if}

    in the page ‘image-2’ isn’t inserted but it is rendering the template ‘_js-slide’ anyway.

    this works fine though for actually rendering ‘image-2’ and surrounding elements that I have told to only appear if ‘image-2’ does (divs etc, which arn’t showing in this page because ‘image-2’ isn’t).

    Is there a different way of only conditionally adding templates?

    Thanks.

  • #2 / Apr 19, 2011 12:20pm

    smartpill

    456 posts

    It might be a parsing order issue. Have you tested the conditional with a simple:

    {if image-2}IMAGE-2 EXISTS!{/if}

    to see if it’s the conditional? If that text shows it’s possible there is a character within the image-2 field that you don’t see.

    If it is a parsing order issue, meaning the embed is getting processed before the conditional is checked you could take the conditional and move it to the embed, like:

    //IN MAIN TEMPLATE REMOVE CONDITIONAL & PASS VARIABLE THROUGH EMBED
    {embed="globals/_js-slide" image_test="{image-2}"}
    //IN _js-slide template
    {if "{embed:image_test}" !=""}content of template…{/if}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases