Since we now want to use the documents in the cms in the template menus, we have to change the way the menus are selected, To do this, we will change the context view once more to take the cms into consideration. In the new solution we want to keep the contact page from the first iteration since that has a for for sending mail, but to home page and about page should be highlighted in the menu when opened from the cms. This is how it can be solved.

Context view handling the cms

First of all the contact can be handled as before, but home and about gives back cms as current. We can use that to do a check for the used slug when pages form the cms is shown and add that to a different livetext.

path = request.get_full_path()[1:-1] # remove the leading and trailing /
current = path.split('/')[0]
ctx[ 'current'] = current
if current == 'cms':
        slug = request.GET.get('slug')
        ctx['slug'] = slug

The new code in context view

   <div class="navbar-collapse collapse">
     <ul class="nav navbar-nav">
       <li class="{% if slug == "landing-page" %}active{% endif %}"><a href="/cms/viewarticle/?slug=landing-page">Home</a></li>
       <li class="{% if slug == "about" %}active{% endif %}"><a href="/cms/viewarticle/?slug=about">About</a></li>
       <li class="{% if current == "contact" %}active{% endif %}"><a href="/contact/">Contact</a></li>

The new menu code in the template

Make sure the default page is the right one

When we created the first version of the solution, we selected the landing page as the default page for the application. It still is, so when we first visits the cms, we will start with the old page and not the new editable page form the Articles table. Since we can not select a page with a query string as the default page, we have to make the landing page do a redirect the the new landing page in the CMS. This is how to do it.

  1. Open the original landing page
  2. Change the redirect in page properties settings tab to /cms/viewarticle/?slug=landing-page by first selecting the /cms/viewarticle/ from the dropdown and then add the page query string ?slug=landing-page