Navigating through Expression Engine and utilizing conditional statements

Would greatly appreciate some assistance with this issue. I am working on an Expression Engine website and encountering difficulties with simple conditionals for navigation active states. Despite having a color state designated within the styles, there seems to be a problem with the actual "if statements" themselves as they are not rendering correctly in the code when inspected (the navigation is embedded).

<nav class="group" role="navigation">
    <ul id="nav" class="group">
        <li class="first"><a {if segment_1 == ""} class="active" {/if}  href="{site_url}"><strong>Now</strong></a></li>
        <li><a {if segment_1 == "articles"} class="active" {/if} href="/articles/"><strong>articles</strong></a></li>
        <li><a {if segment_2 == "readings"} class="active" {/if} href="/book-readings/readings"><strong>books</strong></a></li>
        <li class="last"><a {if segment_2 == "readings"} class="active" {/if} href="/shelf/readings"><strong>shelf</strong></a></li>
    </ul>
</nav>

Answer №1

Give this a try:

<nav class="group" role="navigation">
    <ul id="nav" class="group">
        <li class="first"><a {if "{segment_1}" == ""} class="active" {/if}  href="{site_url}"><strong>Now</strong></a></li>
        <li><a {if "{segment_1}" == "articles"} class="active" {/if} href="/articles/"><strong>articles</strong></a></li>
        <li><a {if "{segment_2}" == "readings"} class="active" {/if} href="/book-readings/readings"><strong>books</strong></a></li>
        <li class="last"><a {if "{segment_2}" == "readings"} class="active" {/if} href="/shelf/readings"><strong>shelf</strong></a></li>
    </ul>
</nav>

To clarify, you mentioned:

they render in the code

My understanding was that you were referring to all of them, hence I suggested wrapping the variables in quotes and curly brackets. However, there may be an issue with the last 2 conditions always being matched together. If this is indeed the problem, then you should compare both segments like this:

        <li><a {if "{segment_1}" == "book-readings" && "{segment_2}" == "readings"} class="active" {/if} href="/book-readings/readings"><strong>books</strong></a></li>
        <li class="last"><a {if "{segment_1}" == "shelf" && "{segment_2}" == "readings"} class="active" {/if} href="/shelf/readings"><strong>shelf</strong></a></li>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for creating this image using HTML and CSS?

Looking to style an image using HTML and CSS. This is what I attempted: <span>$</span><span style="font-size: 50px;">99</span><span style="vertical-align: text-top;">00</span> However, the result doesn't ma ...

Reposition picture "overlays" additional HTML components

I am struggling with rotating an image by clicking on a button as the image overlaps the buttons. Can anyone provide guidance on how to achieve this without overlapping? For reference, here is my code and an example: here (http://jsfiddle.net/jj03b17n/5/) ...

uniformly distribute the list items on the horizontal navigation bar

Does anyone know how to properly space out a ul in a navigation bar, with 5px padding on the right and left and the text evenly spaced in between? body { background: #ffffff; text-align: center; font-family: helvetica, arial, san ...

Displaying an image that spans the entire width of the browser

I'm currently working on a WordPress site and have encountered an issue with the header image. I want it to span the full width of any browser window. The existing code in the parent theme is as follows: background: url("/test/wp-content/themes/Howt ...

Optimizing the speed and load performance of SQLite in Phonegap

As someone who is new to Android programming, I am seeking advice on how to optimize the performance of my phonegap SQLite application. Currently, it takes 30 seconds to load 150 words when I hit the refresh button. Can anyone provide tips on how to enhanc ...

What value is used as the default for justify content?

MDN states that the default value of justify-content is normal, even though it's not listed in the accepted values. What exactly does a normal value mean? normal This means that items are packed in their default position as if no justify-cont ...

The HTML button fails to respond when clicked

My website development process has hit a snag with the header buttons not functioning properly. I suspect the issues lie within lines 12 to 15 of the code snippet below: <!DOCTYPE html> <html> <head> <script src="https: ...

Specify the location of the resize button (corner)

Scenario : At the bottom of the page, there is a resizable textarea, However, having the resize button at the bottom-right corner does not provide the best user experience (try it out), Issue : I am wondering if there is a way to move the resize butt ...

When the content in one box exceeds the content in the other, one box is considered to be overfilled

For the image, click here: I am facing an issue with boxes stacking on top of each other. When one box has more content, it overlaps the other. CSS: #destaques_container{ margin: 0 auto; } #destaques_container_dentro{ float: left; margi ...

The properties of margin:auto and text-align:center are failing to function as expected

I'm facing an issue while creating a website. The 'margin: auto' and 'text-align: center' properties in my CSS code seem to not be functioning as expected. Can someone please review my code in inspect element and identify the probl ...

Efficiently refine your search using the combination of checkboxes and dropdown menus simultaneously

I am currently in the process of creating a highly sortable and filterable image gallery that utilizes numerous tags. The inspiration for this project stems from a similar question on Stack Overflow regarding dropdown menus and checkboxes. You can view the ...

Display the contents of a <div> tag from one HTML file onto another HTML file

Recently I embarked on learning HTML and came across a peculiar doubt. My goal is to create a section div on the first page that changes dynamically based on the menu item clicked, rather than redirecting to another HTML page. I've experimented with s ...

Designing a dynamic button with changing colors using html and css

Is there a way to design a button with a starting color of red, but changes to orange when the mouse hovers over it? I am looking to add this type of button to my website. ...

Having trouble displaying an image in your React project?

I'm having an issue with my code where the logo is not displaying, even though it should be in the src -> pages -> images folder. I can't seem to figure out why this is happening. import dress from "./images/dress.png"; const I1 = () => ...

ASP.NET showcases icons in a distinct manner compared to HTML and CSS

I'm encountering an issue while trying to convert HTML/CSS to ASP.NET. In the original HTML, the icons were arranged in a single row of four icons, and for mobile devices, they were displayed in 2x2 rows. When I attempted to copy and paste the HTML wi ...

Drag a spinning cube using CSS and Jquery when the mouse is pressed

I'm attempting to develop a dynamic rotating cube that users can manipulate to their desired side by clicking and dragging on the cube. Currently, I have functionality where the cube moves as the mouse cursor moves across the screen, but this results ...

Tips for concealing overflow x on a responsive website

Could use some help here. Whenever I switch to responsive mode, the overflow x feature gets enabled and I'm at a loss on how to disable it. I've attempted using @media to disable overflow but unfortunately it's not working as expected. ...

What is the best way to create a scrollable nested div?

Link to Image My goal is to keep the red section fixed while allowing only the blue section to scroll when there is overflow. The red section consists of two divs. I have attempted using position: fixed to achieve this, but encountered issues such as ove ...

Ways to shut down a pop-up

Can someone assist me with how to close the bio-info popup and implement it in the code provided below? The HTML file: <ul class="ch-grid"> <li> <div class="bioinfo"> <h2>tooltips</h2> /div> The CSS file: .bioinfo { ...

Creating a CSS path that incorporates two conditions simultaneously

I'm currently facing a challenge with finding the CSS path in this scenario: There are over 20 child nodes, and I need to identify every node that has fill attribute not equal to none. I understand that I can target a specific node using :nth-child( ...