{% if topic.name == 'My topic name ' %} not working

Hello everyone !

I am trying to display on a blog:

- the blog title on the blog homepage

- the article title on each article page

- the topic title on each topic page

- a topic-specific description on each topic page (a different description for each topic page).

The support and the HubL Reference helped me a lot for the 3 first parts, but i have an issue for the last one, it seems the " {% if topic.name == ‘topic name’ %}" isn’t working. Here’s the code :

{% if topic %}
{% if topic.name == ‘topic name 1’ %}
<h1>Topic 1</h1>
<p class=“topic-description”>Topic 1 description</p>
{% elif topic.name == ‘topic name 2’ %}
<h1>Topic 2</h1>
<p class=“topic-description”>Topic 2 description</p>
{% elif topic.name == ‘topic name 3’ %}
<h1>Topic 2</h1>
<p class=“topic-description”>Topic 3 description</p>
{% else %}
<h1>{{ topic|replace(“-”," ")|title }}</h1>
{% endif %}

{% elif blog_author %}
<h1>{{ blog_author.display_name }}</h1>

{% else %}
<h1>{{ page_meta.html_title }}</h1>
{% endif %}

Is there something wrong with {% if topic.name == ‘topic name x’ %} ?

Thanks a lot !

Clément.

@Clement,

There shouldn’t be an issue using this type of logic, I have that condition many times before. You do have to watch for things like spelling, spacing, and captilization though because “smart marketing”, “Smart Marketing”, “smart-marketing”, and “Smart-Marketing” are not the same thing. I like to convert my variables to lower case:

{% if topic.name|lower == ''Topic Name"|lower %}

You should probably try to clean up with variables too:

{% set topic1 = "Topic Name 1" %}
{% set topic2 = "Topic Name 2" %}
{% set topic3 = "Topic Name 3" %}
{% set topic4 = "Topic Name 3" %}

@Jsum
Thanks a lot for the help. I tried to make it work with the lower case conversion, but it still didn’t work.

I ended up switching “topic.name” into “topic” and used the url (slug?) instead of the name, now it works just fine.

Here’s the final working solution if someone needs the same kind of functionnality :

{% if topic %}

	{% if topic == 'topic-1' %}
	<h1>Topic 1</h1>
	<p class="topic-description">Topic 1 description</p>

	{% elif topic == 'topic-2' %}
	<h1>Topic 2</h1>
	<p class="topic-description">Topic 2 description</p>

	{% elif topic == 'topic-3' %}
	<h1>Topic 3</h1>
	<p class="topic-description">Topic 3 description</p>

	{% else %}
	<h1>{{ topic|replace("-"," ")|title }}</h1>

	{% endif %}

{% elif blog_author %}
	<h1>{{ blog_author.display_name }}</h1>

{% else %}
	<h1>{{ page_meta.html_title }}</h1>

{% endif %}

Thanks again for looking into this and have a nice day !