Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Trouble with categories group_id

Status Resolved
Add-on / Version Publisher 2.11.1
Severity
EE Version 5.2.6

Werner Gusset

Aug 08, 2019

I rebuild part of an old site and get in trouble with a conditional around categories and group_id.

This is the code that works on an old non Publisher site

{exp:channel:entries channel=....}
  {categories show_group="2"}
    {if category_id == "11"}
      <i class="far fa-file-video"></i> {category_name}
    {if:else}
      <i class="far fa-file-pdf"></i> {category_name}
    {/if}
  {/categories}
{exp:channel:entries}

and this on the new Publisher site does not work. It outputs template code after the opening exp:publisher:translate_category tag

{exp:channel:entries ...}
{exp:publisher:translate_category group_id="2"}
  {if cat_id == "11"}
    <i class="far fa-file-video"></i> {cat_name}
  {if:else}
   <i class="far fa-file-pdf"></i> {cat_name}
  {/if}
{/exp:publisher:translate_category}
{/exp:channel:entries}

What have I done wrong?

#1

Werner Gusset

Maybe need to add that there are 3 category groups in that channel.

#2

BoldMinded (Brian)

Try adding a var prefix, it’s probably confused when parsing the variables.

{exp:channel:entries ...}
{exp:publisher:translate_category group_id="2" var_prefix="cat:"}
  {if cat:cat_id == "11"}
    <i class="far fa-file-video"></i> {cat:cat_name}
  {if:else}
   <i class="far fa-file-pdf"></i> {cat:cat_name}
  {/if}
{/exp:publisher:translate_category}
{/exp:channel:entries}
#3

Werner Gusset

I have this

{exp:publisher:translate_category group_id="2" var_prefix="cat:"}
   {if cat:cat_id == 11}
  <i class="far fa-file-video"></i> {cat:cat_name}
  {if:else}
  <i class="far fa-file-pdf"></i> {cat:cat_name}
   {/if}
 {/exp:publisher:translate_category}

The conditional does not work. Gets the icon from the else part. It outputs “{cat:cat_name}”

#4

BoldMinded (Brian)

Does it work if you don’t use the conditional?

#5

Werner Gusset

It ouputs “{cat:cat_name}”

I suspect the parameter group_id=”2”. This is not mentioned in your doc.

#6

BoldMinded (Brian)

Yeah, group_id is not a valid parameter, it should be cat_id.

BTW, I have a very similar template tag in one of my production sites and it parses correctly, so I don’t think there is a bug here. Try the cat_id parameter.

#7

Werner Gusset

And what exactly would I try?

#8

Werner Gusset

I don’t know the cat_id. Or should I put all cat_ids from group_2 in there?

#9

BoldMinded (Brian)

You need to know the category id, that is the only way that tag works.

#10

BoldMinded (Brian)

Usually that tag is used inside of a categories tag pair of some sort, or you know the category id and hardcode the cat_id parameter. I should have realized sooner that group_id is not a valid parameter.

#11

Werner Gusset

Good Brian

I missunderstood the tags functionality. The code that solved my problem is:

{categories show_group="2"}
 {if category_id == "11"}
  <i class="far fa-file-video"></i>
 {if:else}
  <i class="far fa-file-pdf"></i>
 {/if}
 {exp:publisher:translate_category cat_id="{category_id}"}
  {cat_name}
 {/exp:publisher:translate_category}
{/categories}

Thank you.

#12

BoldMinded (Brian)

Cool, glad we figured it out 😊

Login to reply