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.

conditional to display | between prev/next links only if both prev/next links exist - error

October 06, 2011 3:24pm

Subscribe [2]
  • #1 / Oct 06, 2011 3:24pm

    Sean C. Smith

    3818 posts

    On my page I’ve got two links

    Previous Offer | Next Offer

    that are generated with the following code:

    {exp:channel:prev_entry channel="offers"}
     <a href="http://{path=%27offers/article%27}" title="Previous Offer | {title}">PREVIOUS OFFER</a>
    {/exp:channel:prev_entry}
          
     |
          
    {exp:channel:next_entry channel="offers"}
     <a href="http://{path=%27offers/article%27}" title="Next Offer | {title}">NEXT OFFER</a>
    {/exp:channel:next_entry}

    What I’m trying to do is get the pipe | to not appear if on the first or last entry. To do this I’ve set up two snippets

    {prev}
    with the code for the previous link

    and {next}
    with the code for the next link

    I then tried a number of conditionals around the pipe | but I keep getting the following error

    Parse error: syntax error, unexpected ‘<’ in /var/www/vhosts/wavecrestresorts.com/httpdocs/wavesys/expressionengine/libraries/Functions.php(656) : eval()‘d code on line 51

    code looks like this and a couple of other variations

    {if "{next}" !='' AND "{prev}" !=''}|{/if}

    If I put single quotes around {next} and {prev} the page renders without an error but the pipe | displays even when there is only one of prev/next links.

    Any thoughts?

  • #2 / Oct 10, 2011 12:17am

    glenndavisgroup

    436 posts

    Hi Sean,

    I’m not sure if this is the correct answer but you might want to use some CSS and JavaScript to make this work as I don’t see any other options for these tag pairs. Try doing something like the following.

    Step-1:
    - At the top of the page define 2 Boolean JavaScript variables for your next and previous links:

    [removed]
    var blnNext = false;
    var blnPrev = false;
    [removed]

    - Next create a style for your pipe character like the following:

    <style>
    #pipechar{
      display: none;
      ...
    }
    </style>

    Step-2:
    - Add some JavaScript in your next and prev tags and a span to your pipe character with an id so we can control it using jQuery and CSS. This will look like so:

    {exp:channel:prev_entry channel="offers"}
     <a href="http://{path=%27offers/article%27}" title="Previous Offer | {title}">PREVIOUS OFFER</a>
     [removed]
     var blnPrev = true;
     [removed]
    {/exp:channel:prev_entry}
          
    <span> | </span>
          
    {exp:channel:next_entry channel="offers"}
     <a href="http://{path=%27offers/article%27}" title="Next Offer | {title}">NEXT OFFER</a>
     [removed]
     var blnNext = true;
     [removed]
    {/exp:channel:next_entry}

    Step-3:
    - Last we need to add some jQuery code to take care of displaying the pipe character. Do something like this:

    $(document).ready(function(){
       if(blnNext && blnPrev)
          $('#pipechar').css({"display":"block"});
    });

    As I said this could be the wrong way of doing it but it’s an option. I hope that helps.

    Mike

  • #3 / Oct 11, 2011 9:04am

    Sean C. Smith

    3818 posts

    THanks, I’ll give that a shot later today.

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

ExpressionEngine News!

#eecms, #events, #releases