Method: Mtl::Rails::ViewHelpers#mtl_header

Defined in:
lib/mtl/rails/view_helpers.rb

#mtl_header(title = translate('.title', default: 'Menu'), **options) { ... } ⇒ String

Renders a specialized template for the header.

Parameters:

  • title (String) (defaults to: translate('.title', default: 'Menu'))

    with the header to display, when set to ‘false` or an empty string, the rendering of the `<h1>` tag is skipped. By default it tries to use a translation via `.title` key

  • back (String, Boolean)

    (URL) with a link to return to the previous view, when this string is present, then the menu is skipped and this link is always present

  • menu (String, Boolean)

    (HTML ID) references the id of the aside menu / default nav menu to show / hide on mobile devices. The default used is ‘nav-menu`. When set to `false`, this button is skipped.

  • class (String, Array)

    (HTML CLASS) additional, custom css class on header

Yields:

  • Additional content to be rendered as part of the header, with a navbar object as argument, to also build the extended navigation if needed (by passing another block to nav.extended)

Returns:

  • (String)

    HTML safe string



363
364
365
366
367
368
369
370
371
# File 'lib/mtl/rails/view_helpers.rb', line 363

def mtl_header(title = translate('.title', default: 'Menu'), **options, &block)
  mtl_class = ['mtl-layout-default-header', options[:class]].compact.flatten.join(' ')
  mtl_nav = NavbarPresenter.new(self)
  mtl_content = block_given? ? capture(mtl_nav, &block) : nil
  render file: 'mtl/header', locals: { mtl_title: title.presence, mtl_back: options.fetch(:back, false),
                                       mtl_menu: options.fetch(:menu, 'nav-menu'),
                                       mtl_fixed: options.fetch(:fixed, false), mtl_class: mtl_class,
                                       mtl_nav: mtl_nav, mtl_content: mtl_content }
end