-
Notifications
You must be signed in to change notification settings - Fork 136
Renderer::Text
Simon Courtois edited this page May 2, 2014
·
1 revision
The Text renderer does not generate any HTML markup, but only renders the navigation items as plain text (similar to breadcrumbs, but without any links etc.). This can be used for creating dynamic page titles.
Consider this navigation again:
SimpleNavigation::Configuration.run do |navigation|
navigation.items do |primary|
primary.item :books, 'Books', books_path do |books|
books.item :fiction, 'Fiction', fiction_books_path
books.item :history, 'History', history_books_path
books.item :sports, 'Sports', sports_books_path
end
primary.item :music, 'Music', musics_path
primary.item :dvds, 'Dvds', dvds_path
end
end
When rendered as text and the second level item :sports
is active, the text renderer outputs the active primary navigation and the active subnavigation as plain text concatenated with a customizable character, i.e.:
Books - Sports
You can pass the following options to render_navigation
when using the text renderer:
-
:renderer
- set to:text
to use the text renderer -
:join_with
- to specify the character or string which should be used to join your items (defaults to' '
). If you change this option, do not forget to also specify the whitespace around your join character, e.g.join_with: ' > '
. It's safer to use escaped HTML characters when using special characters. You could even consider to escape the whitespace (join_with: ' > '
).
To set a dynamic page title based on your current navigation, you can use code like this (using HAML):
%html
%head
%title= 'My site name - ' + render_navigation(renderer: :text, join_with: ' - ')
%body
/ ...