1

I have a basic expressionengine template which I am using to display entries for 2 different channels. I am using an embed to pass different page layouts within the center of the template, this is based on conditionals.

{exp:channel:entries channel="dog|cat" limit="1" dynamic="yes"}
  (basic html here)
    {if channel == "dog"}
      {embed="tg/one"}
    {if:elseif channel == "cat"}
      {embed="tg/two"}
    {/if}
  (some basic html here)
{/exp:channel:entries}

I have also tried using..

{exp:channel:entries channel="dog|cat" limit="1" dynamic="yes"}
  (basic html here)
    {if category_id == "100"}
      {embed="tg/one"}
    {if:elseif category_id == "200"}
      {embed="tg/two"}
    {/if}
  (some basic html here)
{/exp:channel:entries}

When loading the final page, the parent template displays fine but doesn't show the appropriate embed or any embed for that matter.

It's probably worth noting that the embeds do not contain any expressionengine code, just html. Could someone please explain what I am doing wrong or the best method to accomplish this?

Thanks

4

Robert!

First of all, let's fix your conditionals.

Conditionals using numbers don't need quotation marks. From docs:

If you are testing against a word, you should enclose the word in single or double-quotes. If you are testing against a number, then you do not need to use quotes.

So:

{if category_id == 100}

Even so, this code doesn't work because {category_id} is available just inside the {categories} variable pair.

The better way to compare the name of a channel is using its short_name. Usually the name is titlecase or it has special characters. So:

{if channel_short_name == "dog"}

Now, I suggest you to just use embeds if you really need them. Since you just need HTML on them, try to use a global_variable, for better performance.

| improve this answer | |
  • Robson, Thanks for the detailed explanation. I see where I went wrong now. I'm also going to work on implementing this using a global_variable. Thanks Again! – Robert Jun 6 '13 at 21:59

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.