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.

Using embed in conditional

February 11, 2012 2:32pm

Subscribe [1]
  • #1 / Feb 11, 2012 2:32pm

    walpow

    133 posts

    I’m trying to use an embed within a conditional to control whether some navigation links appear as text or links. At first I was testing for no result. This didn’t work. So I changed the embed to return an x if there were no results. Testing has shown this is working. But when I stick the same code that returned the x into a conditional, it doesn’t work. I’ve tried a bunch of variations of single and double quotes and this is one that at least gets parsed; but I can’t get it to make it recognize the x and give me the code without the links. It always takes the if:else route. Suggestions?

    {if "embed='embeds/.serial-next the-entry='{entry_id}' the-serial='{related_entries id="series"}{entry_id}{/related_entries}'" == "x"}
       (code that makes the nav text appear as text)
    {if:else}
       (code that makes the nav text appear as links)

    Edit: After I posted I tried to do this with PHP, and I’m getting a similar result. I’m able to echo the result of the no-results embed, but when I use it in a PHP if statement it doesn’t recognize it and always give the if:else route.

    <?php
        $next_page = '{embed="embeds/.serial-next the-entry="{entry_id}" the-serial="{related_entries id="series"}{entry_id}{/related_entries}"}';
        if ( $next_page == "x" )
         {echo "(code that makes the nav text appear as text)";}
        else
         {echo "(code that makes the nav text appear as links)";}
     ?>
  • #2 / Feb 12, 2012 8:22pm

    Dan Decker

    7338 posts

    Hi walpow,

    I’m trying to wrap my head around exactly what you want to do here.

    So I changed the embed to return an x if there were no results.

    Can you expand a bit on what you did here?

    I’m sure there is a way to get what you need, I just need a little more context. Can you share the code that triggers your navigation as well?

    Thanks!

  • #3 / Feb 12, 2012 9:38pm

    walpow

    133 posts

    I eliminated the whole problem by going at it a whole ‘nother way. But for the sake of explanation ... the embed returns the next in a series of items, giving me information I need to construct a “next” link (and another embed gives me info for a “last” link). But if the embed doesn’t find a next one, I know the one we’re working with is the last, and I want the words “next” and “last” to appear as straight text, not as links.

    But when testing for no next item found - either by letting the embed return a null or making it return a specific string (in this example, x) if no result was found, neither the EE if nor the PHP if was able to successfully use the result in a comparison ... even though other code told me with both EE and PHP that the x was being returned. In other words, I was getting the proper signal back from the embed, but I couldn’t use it to direct the code to do what I wanted.

    By the way, what I did instead was to add a status of “last.” It turned out doing so let me do some other stuff I wanted to do, and solved this problem too.

    So you may close at will ...

    Thanks,
    Nathan

  • #4 / Feb 13, 2012 8:09pm

    Sean C. Smith

    3818 posts

    Nathan,

    Glad to see you were able to resolve this on your own. Am closing this thread at your request. Feel free to post again when you need more help.

    Sean

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

ExpressionEngine News!

#eecms, #events, #releases