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.

Has anyone experienced the following problem? A conditional if statement leaving trailing characters E.G. {/if

September 03, 2010 8:22am

Subscribe [5]
  • #1 / Sep 03, 2010 8:22am

    Hi, Has anyone experienced a trailing {/if string being output from a nested conditional statement as per the following example? I would be very grateful to know if this is to do with my code or some unexpected behaviour by EE. Thanks in advance of any opinions. Jack

    {if embed:category_id != "" AND embed:channel_name != ""}
      <div id="LinksToPages">
        {exp:channel:entries channel="{embed:channel_name}" category="{embed:category_id}" dynamic="off" orderby="general_content_navigation_order" sort="asc" backspace="6"}
         {if general_content_exclude_from_nav == ""}
           <a href="http://index.php?/{segment_1}/{entry_id}" title="{title}">{title}</a> |
         {/if}
      {/exp:channel:entries}
      </div>
    {/if}
  • #2 / Sep 03, 2010 9:54am

    Ingmar

    29245 posts

    Welcome to the forums, Jack! What version and build of EE are you using? Any extensions? Do you’ve got a link to the site?

  • #3 / Sep 03, 2010 10:07am

    Hi Ingmar,

    I’m using version 2.1 and no extensions are installed. I think the issue is related to the backspace parameter of the channel tag. For example if I do not use the backspace parameter there is no trailing {/if at all.

    The build is number 20100810.

    Thanks, Jack.

  • #4 / Sep 03, 2010 11:03am

    Ingmar

    29245 posts

    Good catch! Yes, that would make sense: Backspacing removes characters from the last iteration of the channel entries loop. In your case, that’s at least part of the {/if} clause. You might have to re-arrange your code slightly.

  • #5 / Sep 03, 2010 11:11am

    Thanks Ingmar,

    I’m going to add white space characters after the ending {/if} to protect it and use backspace to trim off my vertical link separator and see what happens.

    Thanks for the replies.

    Best…Jack

  • #6 / Sep 03, 2010 11:25am

    Ingmar

    29245 posts

    Makes sense. Let us know if that does it for you.

  • #7 / Sep 03, 2010 1:02pm

    Hi Ingmar,

    I’ve changed the layout of my links for now as however I configure the structure of the code I would need to trim the last link separator off and would still have the same problem. Thanks for you comments and help.

    Best…Jack

  • #8 / Sep 03, 2010 3:43pm

    Sue Crocker

    26054 posts

    Jack, have you considered one of the available find and replace plugins to get around this problem?

  • #9 / Sep 04, 2010 8:48am

    Not yet. Can you suggest anything?

    Thanks, Jack

  • #10 / Sep 05, 2010 3:02pm

    Greg Salt

    3988 posts

    Hi Jack,

    If ‘general_content_exclude_from_nav’ is a custom field in the embedded channel (which it seems to be based on your code), have you tried restructuring your code like this:

    {if embed:category_id != "" AND embed:channel_name != ""}
      <div id="LinksToPages">
        {exp:channel:entries channel="{embed:channel_name}" search:general_content_exclude_from_nav="IS_EMPTY" category="{embed:category_id}" dynamic="off" orderby="general_content_navigation_order" sort="asc" backspace="6"}
           <a href="http://index.php?/{segment_1}/{entry_id}" title="{title}">{title}</a> |
      {/exp:channel:entries}
      </div>
    {/if}

    You could then the backspace parameter or perhaps another conditional to test for the count being equal to the total_results.

    Cheers

    Greg

  • #11 / Sep 05, 2010 4:37pm

    Thanks for that Greg. The search option for that tag is new to me so I’ll give it a try.

    Cheers, Jack

  • #12 / Sep 06, 2010 2:12am

    John Henry Donovan

    12339 posts

    Let us know how you get on with Greg’s suggestion

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

ExpressionEngine News!

#eecms, #events, #releases