Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set "active" class in navigation sidebar #75

Open
Tectu opened this issue Oct 12, 2020 · 0 comments
Open

Set "active" class in navigation sidebar #75

Tectu opened this issue Oct 12, 2020 · 0 comments

Comments

@Tectu
Copy link

Tectu commented Oct 12, 2020

I am implementing a simple portal using CppCMS. The master page has a simple sidebar for navigational purposes based on the W3C example.

My master template looks like this (mainly the sidebar template is of interest):

<% c++ #include "data/content.hpp" %>
<% skin defskin %>
<% view master uses content::master %>

<% template title() %>
    <%= title %>
<% end template %>

<% template page_content() %>
    Override  Me
<% end template %>

<% template sidebar() %>
    <div class="sidebar">
      <a class="active" href='<% url "/" %>'>Home</a>
      <a href='<% url "/news" %>'>News</a>
      <a href='<% url "/users" %>'>Users</a>
    </div>
<% end template %>

<% template render() %>
    <html>
        <head>
            <link rel="stylesheet" href="/css/style.css">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title><% include title() %></title>
        </head>
    <body>

        <% include sidebar() %>

        <div class="content">
            <h1><% include title() %></h1>
            <% include page_content() %>
        </div>
    </body>
</html>
<% end template %>

<% end view %>
<% end skin %>

What is the appropriate/recommended way of setting the class="active" attribute for the URL of the current view/page? Is there a mechanism in the template engine that allows me to set the attribute on the appropriate menu item in the master template?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant