0

Does anyone know if something like this is possible:

{exp:channel:entries channel="choices_events|jobs-opps" show_future_entries="yes" show_expired="no" disable="trackbacks" orderby="date_time|job-start-date" sort="asc" paginate="bottom" status="open" dynamic="no" parse="inward" {if channel_short_name == "jobs-opps"}category="258"{/if}

So I've got 2 channel entries that I want to list 'choices_events' and 'jobs-opps'. If the entries are under 'jobs-opps' I only want to display the 'jobs-opps' within the category '258'.

The above code isn't working for me at the moment.

Julie

1

There's 2 issues here, the first is using a conditional inside the tag parameters, the second is as @Siebird has mentioned, you can't reference {channel_short_name} outside of the channel entries tag pair.

One solution as @Siebird mentioned is to use a segment, which would be preferable, the other is to do another channel entries but that would only work for the embedded approach. For the conditional answer, I've referenced {channel_short_name} which obviously won't work, but I've given a complete solution at the bottom.

Two possible ways that come to mind to resolving the conditional, the duplicate:

{if channel_short_name == "jobs-opps"}
    {exp:channel:entries channel="choices_events|jobs-opps" 
        show_future_entries="yes" show_expired="no" 
        disable="trackbacks" orderby="date_time|job-start-date" 
        sort="asc" paginate="bottom" status="open" dynamic="no" 
        parse="inward" category="258"}
    ...
    {/exp:channel:entries}
{if:else}
    {exp:channel:entries channel="choices_events|jobs-opps" 
        show_future_entries="yes" show_expired="no" 
        disable="trackbacks" orderby="date_time|job-start-date" 
        sort="asc" paginate="bottom" status="open" dynamic="no" 
        parse="inward"}
    ...
    {/exp:channel:entries}
{/if}

Not great!

Or the embed (which is what I tend to use in this instance):

In the template (or ideally if it has a parent template) have the conditional and the embed...

{if channel_short_name == "jobs-opps"}
    {embed=template-group/my-embed category="category='258'"}
{if:else}
    {embed=template-group/my-embed category=""}
{/if}

Then in the embedded template (template-group/my-embed) used for both has the following...

    {exp:channel:entries channel="choices_events|jobs-opps" 
        show_future_entries="yes" show_expired="no" 
        disable="trackbacks" orderby="date_time|job-start-date" 
        sort="asc" paginate="bottom" status="open" dynamic="no" 
        parse="inward" {embed:category}}
    ...
    {/exp:channel:entries}

Note the embedded variable passing the category parameter.

To resolve the {channel_short_name} issue, simple wrap the first template in the channel entries tag pair:

{exp:channel:entries channel="choices_events|jobs-opps" disable="trackbacks"
    status="open" dynamic="no" limit="1"}
    {if "{channel_short_name}" == "jobs-opps"}
        {embed=template-group/my-embed category="category='258'"}
    {if:else}
        {embed=template-group/my-embed category=""}
    {/if}
{/exp:channel:entries}

You will need to tweak the parameters a little, as it's not obvious as to what you're outputting on what URLs, you're listing multiple entries, but unknown if these could be from both channels at the same time, or separate channels depending on the URL. so currently the parent is limited to 1 loop, whereas the embedded templates will loop through everything.

1
  • Thanks Peter. I went with the embedded template in the end. Works really well. May 30 '13 at 9:05
2

It is, if you're using a global, segment or embed variable. {channel_short_name} is a single variable tag within the channel entries tag.

Is it possible to use a conditional based off the {segment_X}?

{exp:channel:entries 
    channel="choices_events|jobs-opps"
    show_future_entries="yes"
    show_expired="no"
    disable="trackbacks"
    orderby="date_time|job-start-date"
    sort="asc" paginate="bottom"
    status="open"
    dynamic="no"
    parse="inward"
    {if segment_2 == "jobs-opps"}category="258"{/if}
}
3
  • You cannot have a conditional inside the tag parameters. May 29 '13 at 12:47
  • Yes you can, as long as they are simple conditionals with global, segment or embed variables. Simple conditionals get parsed at stage 3, and module tags get parsed at stage 5. See parse order for more info: loweblog.com/downloads/ee-parse-order.pdf
    – Siebird
    May 29 '13 at 13:20
  • Learn something new everyday, thanks for clarifying! Good breakdown and explanation here: johndwells.com/blog/… Also another solution using the ifelse add-on. May 29 '13 at 13:36
0

I think, you can do it without having if condition within the channel entry tag by just having NOT with all the categories except 258 of that channels category group like:

{exp:channel:entries 
    channel="choices_events|jobs-opps" 
    show_future_entries="yes" 
    show_expired="no" 
    disable="trackbacks" 
    orderby="date_time|job-start-date" 
    sort="asc" 
    paginate="bottom" 
    status="open" 
    dynamic="no" 
    category="not 250|251|252|253|254|254|255|256|257|259"}

I understand there may be a number of categories with NOT but you can reduce it by having category_group="not 1|2|3" parameter.

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.