4

I am trying to do something that seems as if it should be simple but it's baffling me!

I have a template page that needs to embed something different depending on the URL.

There are three possible cases.

Case one is that segment_2 is blank. In this case I need to embed option A. Simple enough I think.

In Case two, segment_2 is not blank and contains the url_title of one of the products in this channel. I know the channel. I need to embed option B.

In case three, segment_2 is not blank and contains something else that is NOT the url_title of one of my products in this channel. Again I know the channel. I need to embed option A - the same as in the first case.

I have tried putting an if inside the exp:channel:entries tag pair, comparing {url_title and {segment_2) - that doesn't seem to work.

Rather than having anyone try to debug my code, how would anyone advise doing this? I am aware that I could be arranging my site in a different way, but I am where I am!

7

Here's a no add-on way of doing this. I'm assuming you're not trying to get pagination going. That would change things.

{if segment_2 == ""}option A embed or direct code{/if}
{if segment_2 != ""}
  {exp:channel:entries channel="products" url_title="{segment_2}" require_entry="yes" ... }
     option B embed passing all variables necessary - or just put code here directly
     {if no_results}option C embed{/if}
  {/exp:channel:entries}
{/if}
1
  • Thank you very much Stephen! I knew there had to be a simple way. I'll delete all the php variables I had there to try and get it going!
    – user2396
    Nov 22 '13 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.