Be sure to checkout our newest add-on Reading Time Pro!

Compatibility updates:

  • Publisher is EE5 compatible, but it does not currently support the Fluid field (it's in the works).

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

Aug 08, 2019

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

#2

BoldMinded (Brian)

Aug 08, 2019

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

Aug 08, 2019

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)

Aug 08, 2019

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

#5

Werner Gusset

Aug 08, 2019

It ouputs “{cat:cat_name}”

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

#6

BoldMinded (Brian)

Aug 08, 2019

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

Aug 08, 2019

And what exactly would I try?

#8

Werner Gusset

Aug 08, 2019

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

#9

BoldMinded (Brian)

Aug 08, 2019

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

#10

BoldMinded (Brian)

Aug 08, 2019

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

Aug 09, 2019

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)

Aug 09, 2019

Cool, glad we figured it out 😊

Login to reply

Contact

For add-on support, please use the Support section. General inquries and pre-sale questions can be sent to support@boldminded.com.