# How to add a conditional logic when on a different url but showing a single post

**URL:** <https://talk.jekyllrb.com/t/how-to-add-a-conditional-logic-when-on-a-different-url-but-showing-a-single-post/9379>\
**Category:** Uncategorized\
**Created:** [August 12, 2024, 8:11am UTC](https://talk.jekyllrb.com/t/how-to-add-a-conditional-logic-when-on-a-different-url-but-showing-a-single-post/9379 "2024-08-12T08:11:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgr8abr](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/dgr8abr/32/6045_2.png) [@dgr8abr](https://talk.jekyllrb.com/u/dgr8abr)\
**Post date:** [August 12, 2024, 8:11am UTC](https://talk.jekyllrb.com/t/how-to-add-a-conditional-logic-when-on-a-different-url-but-showing-a-single-post/9379/1 "2024-08-12T08:11:54Z")

</div>

I had this in my settings.yml

```auto
menu :

      - {name: 'Blogs', url: 'blogs'}
      - {name: 'Work', url: 'work'}
      - {name: 'Books', url: 'books'}
      - {name: 'Projects', url: 'projects'}
      - {name: 'Journal', url: 'journals'}

```

and so I looped it out in my html

```code
  <nav class="nav-links">
              {% for item in site.data.settings.menu %}
                <a href="{{ site.github.url }}/{{ item.url }}" class="text-grey-dark font-sans font-bold no-underline hover:text-black">
                  {{ item.name }} 
                </a>
                {% endfor %} 
              </nav>

```

But what if I want to also add an active class to the Blogs link that starts with ‘/blog/’ url because I have a page that also shows my blog which is the link is like `/blog/blue-sky` not **/blogs/blue-sky**

In the `/blogs` url I show all the blogs but in the `/blog/2024-first-blog` only a single blog is shown.

I want that Blogs link to be highlighted also when I’m on `/blog/**` page.

Thanks in advance, I am asking this because I don’t have the luxury of time to read all the blogs inside this phenomenal page, as I have an another job that reqiures my full attention, I’m just finishing my simple website.

---

<div class="post-metadata">

**Author:** ![george-gca](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/george-gca/32/5301_2.png) [@george-gca](https://talk.jekyllrb.com/u/george-gca)\
**Post date:** [August 13, 2024, 4:46pm UTC](https://talk.jekyllrb.com/t/how-to-add-a-conditional-logic-when-on-a-different-url-but-showing-a-single-post/9379/2 "2024-08-13T16:46:57Z")

</div>

I see 2 possibilities:

- change `url` in your `settings.yml` to be a list instead of a string, so this could look like `- {name: 'Blogs', url: ['blogs', 'blog']}` and when checking for the url to add the active class check with `{% if item.url contains`
- handle the `blog` case individually in your html then handle the other ones in the for loop. This way you could check for `{% if url contains "/blog" %}`

```auto

```

---

<div class="post-metadata">

**Author:** ![dgr8abr](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/dgr8abr/32/6045_2.png) [@dgr8abr](https://talk.jekyllrb.com/u/dgr8abr)\
**Post date:** [August 14, 2024, 12:44am UTC](https://talk.jekyllrb.com/t/how-to-add-a-conditional-logic-when-on-a-different-url-but-showing-a-single-post/9379/3 "2024-08-14T00:44:40Z")

</div>

thank you 4 responding to my question my friend.

but this line :  
`{name: 'Blogs', url: ['blogs', 'blog']}`

isn’t url going to be accepting a string value and not an array ?

---

<div class="post-metadata">

**Author:** ![george-gca](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/george-gca/32/5301_2.png) [@george-gca](https://talk.jekyllrb.com/u/george-gca)\
**Post date:** [August 19, 2024, 6:38pm UTC](https://talk.jekyllrb.com/t/how-to-add-a-conditional-logic-when-on-a-different-url-but-showing-a-single-post/9379/4 "2024-08-19T18:38:58Z")

</div>

In this case `url` would be an array, then you would need to check if the first part of your url is contained in this array. It would work as:

- extract the first part of your page url (/blog/)
- check if it is contained in the list of your urls (/blog/ or /blogs/)
- if it is, highlight this text in the navigation bar

---

<div class="post-metadata">

**Author:** ![dgr8abr](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/dgr8abr/32/6045_2.png) [@dgr8abr](https://talk.jekyllrb.com/u/dgr8abr)\
**Post date:** [August 23, 2024, 7:05pm UTC](https://talk.jekyllrb.com/t/how-to-add-a-conditional-logic-when-on-a-different-url-but-showing-a-single-post/9379/5 "2024-08-23T19:05:33Z")

</div>

yeah got it aalready. !
