Method: ScrivitoHelper#scrivito_tag_list

Defined in:
app/helpers/scrivito_helper.rb

#scrivito_tag_list(tag_name, obj, method_name, options = {}) {|list, child| ... } ⇒ String

Renders a navigation ready for in-place editing.

If a navigation is rendered using this helper method, a special menu is attached to it that lets you change the order of the child pages or insert a new child.

For making the child pages sortable, the parent Obj requires a referencelist attribute named child_order. When creating a page model using the page generator, such an attribute is automatically added to the model.

Examples:

Renders a navigation for an @obj with two children in its toclist, whose titles are “Toys” and “Electronics” respectively:

scrivito_tag_list(:ul, @obj, :toclist, class: "my_list") do |list, child|
  list.tag(:li, class: "my_list_element") do
    link_to(scrivito_path(child)) do
      scrivito_tag(:span, child, :title)
    end
  end
end

#
# Basically, the rendered HTML will look like this:
#
# <ul class="my_list">
#   <li class="my_list_element">
#     <a href="/toys-902b3e8d6ec861c1">
#       <span>Toys</span>
#     </a>
#   </li>
#   <li class="my_list_element">
#     <a href="/electronics-59c6995988ce78f4">
#       <span>Electronics</span>
#     </a>
#   </li>
# </ul>
#

Parameters:

  • tag_name (String, Symbol)

    Name of the outer HTML tag (e.g. :ul or :div).

  • obj (Scrivito::BasicObj)

    The parent Obj, on which method_name will be called in order to fetch the children.

  • method_name (String, Symbol)

    Name of the method to be called on the parent Obj in order to fetch the children. Currently, only toclist is supported.

  • options (Hash) (defaults to: {})

    Options to be passed to content_tag. Use them to add HTML attributes to the tag.

Yield Parameters:

Returns:

  • (String)

    The rendered HTML string.

See Also:



137
138
139
# File 'app/helpers/scrivito_helper.rb', line 137

def scrivito_tag_list(tag_name, obj, method_name, options = {}, &block)
  Scrivito::ChildListTag.new(tag_name, obj, method_name.to_s, self).render(options, &block)
end