<p>The <code>craft_structureelements</code> table contains the data you need to determine the exact position &amp; level of each entry in your structure. But you'd need some fancy plugin logic to attack that data and use it to your advantage.</p>

<p>In all honesty, I really feel like you're going the wrong way on this, and you're better served trying to find a way to make the <code>slug</code> or <code>id</code> work for you. The sole purpose of a slug is to identify a specific page.</p>

<p>How about this...</p>

<p>When you dynamically generate your nav, add a CSS class with slug of that nav item. Then, you can verify that against the slug of the page which is being loaded. Even if the slug changes, it'll change in both places simultaneously.</p>

CC BY-SA 3.0
2015-12-12T00:04:22.273Z
Ah - brilliant! Your suggestion at the bottom on the slug was the ticket. Thanks so much!
dpayne
CC BY-SA 3.0
2015-12-11T23:42:45.297Z
2015-12-11T23:42:45.297Z
Lindsey D
<p>You're going to need some kind of context as to what is "current"; the context you have is in <code>craft.request</code> -- I'm not sure what else you'd use, other than slug / URL / getSegment logic.</p>

CC BY-SA 3.0
2015-12-11T23:26:21.330Z
Right, exactly what I'm struggling with. I provided some additional context for Lindsey D above if that helps.
dpayne
CC BY-SA 3.0
2015-12-11T23:10:25.453Z
2015-12-11T23:10:25.453Z
andrew.welch
<p>I want to conditionally add some CSS to a subnav element if that page in the subnav is currently active. However, I can't add the CSS based on any slug / URL / getSegment logic, as that will likely be changed down the road. I also can't use the ID of the page. </p>

<p>The pages in this subnav are part of the same structure and it seems to me the best way to set the rule would be based on the order of the page in the structure. Something like if page 2 in craft.entries.section('') is active then apply CSS to target element. </p>

<p>Is this possible in Craft? If so, how would I do that? If not, other ideas for how to approach it?</p>

CC BY-SA 3.0
2015-12-11T23:09:15.390Z
Using the entry _position_ is possible, but sounds even sketchier than using a slug. Moving the entry within the structure would instantly break that. Is the entry nested below another entry? Can you use the ID of the _parent_ entry?
Lindsey D
CC BY-SA 3.0
2015-12-11T23:23:52.610Z
@LindseyD I have five entries under one parent. On all pages there is a subnav table with the six entries listed (including the parent). The subnav is ordered sequentially from left to right. The names in the subnav are set by the order of the entries. So if an entry moves from 2 to 3 in order, the 2nd & 3rd names in the subnav change. 

I would like the active entry to be bolded in the subnav, regardless of its position in the table. However, if I set-up the logic to say bold this cell if the ID of the entry is xyz, and its position changes, the same cell is bolded but for a different title.
dpayne
<entries><conditional><order>
Conditionally Applying CSS to Element on Active Page Without Using URL or ID Logic
# Conditionally Applying CSS to Element on Active Page Without Using URL or ID Logic

(Asked by: username_0 on 2015-12-11)

I want to conditionally add some CSS to a subnav element if that page in the subnav is currently active. However, I can't add the CSS based on any slug / URL / getSegment logic, as that will likely be changed down the road. I also can't use the ID of the page.

The pages in this subnav are part of the same structure and it seems to me the best way to set the rule would be based on the order of the page in the structure. Something like if page 2 in craft.entries.section('') is active then apply CSS to target element.

Is this possible in Craft? If so, how would I do that? If not, other ideas for how to approach it?

**Tags:** entries, conditional, order
> **Comments:**
> **username_1**: Using the entry _position_ is possible, but sounds even sketchier than using a slug. Moving the entry within the structure would instantly break that. Is the entry nested below another entry? Can you use the ID of the _parent_ entry?  
> **username_0**: @LindseyD I have five entries under one parent. On all pages there is a subnav table with the six entries listed (including the parent). The subnav is ordered sequentially from left to right. The names in the subnav are set by the order of the entries. So if an entry moves from 2 to 3 in order, the 2nd & 3rd names in the subnav change.   I would like the active entry to be bolded in the subnav, regardless of its position in the table. However, if I set-up the logic to say bold this cell if the ID of the entry is xyz, and its position changes, the same cell is bolded but for a different title.  

---

## 2 answers

### Answer by username_1 on 2015-12-11. Score: 2 | Accepted answer

The `craft_structureelements` table contains the data you need to determine the exact position & level of each entry in your structure. But you'd need some fancy plugin logic to attack that data and use it to your advantage.

In all honesty, I really feel like you're going the wrong way on this, and you're better served trying to find a way to make the `slug` or `id` work for you. The sole purpose of a slug is to identify a specific page.

How about this...

When you dynamically generate your nav, add a CSS class with slug of that nav item. Then, you can verify that against the slug of the page which is being loaded. Even if the slug changes, it'll change in both places simultaneously.

> **Comments:**
> **username_0**: Ah - brilliant! Your suggestion at the bottom on the slug was the ticket. Thanks so much!  

---

### Answer by username_2 on 2015-12-11. Score: 1

You're going to need some kind of context as to what is "current"; the context you have is in `craft.request` -- I'm not sure what else you'd use, other than slug / URL / getSegment logic.

> **Comments:**
> **username_0**: Right, exactly what I'm struggling with. I provided some additional context for Lindsey D above if that helps.  

---

