Measurable Success «10 Checkpoints for Future-Proof Enterprise CMS» White Paper
Measurable Success - White Paper

Generating Page Titles & Using Scrivito's Navigation

Generating Page Titles & Using Scrivito's Navigation

Page titles as HTML titles

To use the title of pages rendered by Scrivito or Solidus as the HTML title, adjust the #index method of the CmsController:

def index
  @title = @obj.title

Now Solidus/Spree will use whatever title is set for the current Scrivito page. Please note that this change can only be observed if you are not logged in as an admin (e.g. in "private"/"incognito" mode).

Replacing Solidus' navigation with Scrivito's

First, create a Deface rule in /app/overrides/spree/shared/main_nav_bar.rb to replace the navigation of Solidus/Spree with a Scrivito partial.

# /app/overrides/spree/shared/main_nav_bar.rb     "spree/shared/_main_nav_bar",
                     replace_contents: "#home-link",
                     name:             "scrivito_main_nav_bar",
                     partial:          "shared/scrivito_main_nav_bar")

Now create the partial that renders the main navigation:

<!-- app/views/shared/_scrivito_main_nav_bar.html.erb -->

<li id="home-link" data-hook>
  <%= link_to Obj.root.display_title, scrivito_path(Obj.root) %>

<%= scrivito_tag_list :span, Obj.root, :toclist do |list, page| %>
  <%= list.tag :li do %>
    <%= link_to page.display_title, scrivito_path(page) %>
  <% end %>
<% end %>

<% if Obj.root.toclist.empty? && scrivito_in_editable_view? %>
  <span>(Hint: Click on the Scrivito icon to the right to create the first subpage.)</span>
<% end %>

Finally, remove the navigation from app/views/page/index.html.erb since the navigation is already rendered in the Solidus context. For this tutorial, remove the first <div>...</div> block from app/views/page/index.html.erb. Afterwards, the content of the file should be this:

<!-- app/views/page/index.html.erb -->

<%= scrivito_tag :h1, @obj, :title %>
<%= scrivito_tag :div, @obj, :body %>

Refresh your page and you will see that the Scrivito navigation bar is integrated with the Solidus style and editable.