Module: Alchemy::PagesHelper

Includes:
BaseHelper, ElementsHelper
Defined in:
app/helpers/alchemy/pages_helper.rb

Instance Method Summary collapse



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'app/helpers/alchemy/pages_helper.rb', line 342

def  options={}
  if @page.blank?
    warning("No Page found!")
    return nil
  end
  default_options = {
    title_prefix: "",
    title_separator: "",
    default_lang: "de"
  }
  options = default_options.merge(options)
  # render meta description of the root page from language if the current meta description is empty
  if @page.meta_description.blank?
    description = Language.current.pages.published.language_roots.try(:meta_description)
  else
    description = @page.meta_description
  end
  # render meta keywords of the root page from language if the current meta keywords is empty
  if @page.meta_keywords.blank?
    keywords = Language.current.pages.published.language_roots.try(:meta_keywords)
  else
    keywords = @page.meta_keywords
  end
  robot = "#{@page.robot_index? ? "" : "no"}index, #{@page.robot_follow? ? "" : "no"}follow"
  meta_string = %(
    <meta charset="UTF-8">
    #{render_title_tag(prefix: options[:title_prefix], separator: options[:title_separator])}
    #{render_meta_tag(name: "description", content: description)}
    #{render_meta_tag(name: "keywords", content: keywords)}
    <meta name="created" content="#{@page.updated_at}">
    <meta name="robots" content="#{robot}">
  )
  if @page.contains_feed?
    meta_string += %(
      <link rel="alternate" type="application/rss+xml" title="RSS" href="#{show_alchemy_page_url(@page, format: :rss)}">
    )
  end
  return meta_string.html_safe
end

#render_meta_tag(options = {}) ⇒ Object

Renders a html tag for name: "" and content: ""

Webdevelopers:

Please use the render_meta_data() helper. There all important meta information gets rendered in one helper. So you dont have to worry about anything.



312
313
314
315
316
317
318
319
320
321
# File 'app/helpers/alchemy/pages_helper.rb', line 312

def render_meta_tag(options={})
  default_options = {
    name: "",
    default_language: "de",
    content: ""
  }
  options = default_options.merge(options)
  lang = (@page.language.blank? ? options[:default_language] : @page.language.code)
  %(<meta name="#{options[:name]}" content="#{options[:content]}" lang="#{lang}">).html_safe
end

#render_navigation(options = {}, html_options = {}) ⇒ Object

Renders the navigation.

It produces a html

structure with all necessary classes so you can produce every navigation the web uses today. I.E. dropdown-navigations, simple mainnavigations or even complex nested ones.

HTML output:

As you can see: Everything you need.

Not pleased with the way Alchemy produces the navigation structure?

Then feel free to overwrite the partials (_renderer.html.erb and _link.html.erb) found in views/navigation/ or pass different partials via the options :navigation_partial and :navigation_link_partial.

Passing HTML classes and ids to the renderer

A second hash can be passed as html_options to the navigation renderer partial.

Example:

<%= render_navigation({from_page: 'subnavi'}, {class: 'navigation', id: 'subnavigation'}) %>

Parameters:

Options Hash (options):

  • show_nonactive (Boolean) — default: false

    Commonly Alchemy only displays the submenu of the active page (if submenu: true). If you want to display all child pages then pass true (together with submenu: true of course). I.e. for css-driven drop down menues.

  • show_title (Boolean) — default: true

    For our beloved SEOs :) Appends a title attribute to all links and places the page.title content into it.

  • restricted_only (Boolean) — default: false

    Render only restricted pages. I.E for members only navigations.

  • reverse (Boolean) — default: false

    Reverse the output of the pages

  • reverse_children (Boolean) — default: false

    Like reverse option, but only reverse the children of the first level

  • deepness (Fixnum) — default: nil

    Show only pages up to this depth.

  • 
    
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    # File 'app/helpers/alchemy/pages_helper.rb', line 149
    
    def render_navigation(options = {}, html_options = {})
      options = {
        submenu: false,
        all_sub_menues: false,
        from_page: @root_page || Language.current_root_page,
        spacer: nil,
        navigation_partial: 'alchemy/navigation/renderer',
        navigation_link_partial: 'alchemy/navigation/link',
        show_nonactive: false,
        restricted_only: false,
        show_title: true,
        reverse: false,
        reverse_children: false
      }.merge(options)
      page = page_or_find(options[:from_page])
      return nil if page.blank?
      pages = page.children.accessible_by(current_ability, :see)
      pages = pages.restricted if options.delete(:restricted_only)
      if depth = options[:deepness]
        pages = pages.where("#{Page.table_name}.depth <= #{depth}")
      end
      if options[:reverse]
        pages.reverse!
      end
      render options[:navigation_partial],
        options: options,
        pages: pages,
        html_options: html_options
    end

    #render_page_layoutObject

    Renders the layout for current page.

    Page layout files belongs in /app/views/alchemy/page_layouts/

    Falls back to /app/views/alchemy/page_layouts/standard if the page_layout partial is not found.

    
    
    47
    48
    49
    50
    51
    52
    # File 'app/helpers/alchemy/pages_helper.rb', line 47
    
    def render_page_layout
      render @page, page: @page
    rescue ActionView::MissingTemplate
      warning("PageLayout: '#{@page.page_layout}' not found. Rendering standard page_layout.")
      render 'alchemy/page_layouts/standard', page: @page
    end

    #render_page_title(options = {}) ⇒ Object

    Returns current page title

    Options:

    prefix: ""                 # Prefix
    separator: ""              # Separating prefix and title
    

    Webdevelopers

    Please use the render_meta_data() helper instead. There all important meta information gets rendered in one helper. So you dont have to worry about anything.

    
    
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    # File 'app/helpers/alchemy/pages_helper.rb', line 274
    
    def render_page_title(options = {})
      return "" if @page.title.blank?
      options = {
        prefix: "",
        separator: ""
      }.update(options)
      title_parts = [options[:prefix]]
      if response.status == 200
        title_parts << @page.title
      else
        title_parts << response.status
      end
      title_parts.join(options[:separator])
    end

    #render_site_layoutObject

    Renders a partial for current site

    Place a rails partial into app/views/alchemy/site_layouts

    and name it like your site name.

    Example:

    <%= render_site_layout %>
    

    renders app/views/alchemy/site_layouts/_default_site.html.erb for the site named "Default Site".

    
    
    66
    67
    68
    69
    70
    71
    # File 'app/helpers/alchemy/pages_helper.rb', line 66
    
    def render_site_layout
      render current_alchemy_site
    rescue ActionView::MissingTemplate
      warning("Site layout for #{current_alchemy_site.try(:name)} not found. Please run `rails g alchemy:site_layouts`")
      return ""
    end

    #render_subnavigation(options = {}, html_options = {}) ⇒ Object

    Renders navigation the children and all siblings of the given page (standard is the current page).

    Use this helper if you want to render the subnavigation independent from the mainnavigation. I.E. to place it in a different area on your website.

    This helper passes all its options to the the render_navigation helper.

    Options:

    from_page: @page                              # The page to render the navigation from
    submenu: true                                 # Shows the nested children
    level: 2                                      # Normally there is no need to change the level parameter, just in a few special cases
    
    
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    # File 'app/helpers/alchemy/pages_helper.rb', line 191
    
    def render_subnavigation(options = {}, html_options = {})
      default_options = {
        from_page: @page,
        submenu: true,
        level: 2
      }
      options = default_options.merge(options)
      if !options[:from_page].nil?
        while options[:from_page].level > options[:level] do
          options[:from_page] = options[:from_page].parent
        end
        render_navigation(options, html_options)
      else
        return nil
      end
    end

    #render_title_tag(options = {}) ⇒ Object

    Returns a complete html tag for the <head> part of the html document.</p> <h3 id="Webdevelopers_">Webdevelopers:</h3> <p>Please use the render_meta_data() helper. There all important meta information gets rendered in one helper. So you dont have to worry about anything.</p> </div> </div> <div class="tags"> </div><table class="source_code"> <tr> <td> <pre class="lines"> 296 297 298 299 300 301 302 303</pre> </td> <td> <pre class="code"><span class="info file"># File 'app/helpers/alchemy/pages_helper.rb', line 296</span> <span class='kw'>def</span> <span class='id identifier rubyid_render_title_tag'>render_title_tag</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='id identifier rubyid_default_options'>default_options</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='label'>prefix:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>separator:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid_default_options'>default_options</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span> <span class='tstring'><span class='tstring_beg'>%(</span><span class='tstring_content'><title></span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_render_page_title'>render_page_title</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_content'></title></span><span class='tstring_end'>)</span></span><span class='period'>.</span><span class='id identifier rubyid_html_safe'>html_safe</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> </div> </div> <div id="footer"> Generated on Tue Apr 14 19:48:15 2026 by <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.41 (ruby-4.0.2). </div> </div> </body> </html> <script src="/cdn-cgi/scripts/7d0fa10a/cloudflare-static/rocket-loader.min.js" data-cf-settings="12e0efd8f84e51bb3225c429-|49" defer></script>