Module: Locomotive::ContentTypesHelper
- Defined in:
- app/helpers/locomotive/content_types_helper.rb
Instance Method Summary collapse
-
#entry_label(content_type, entry, location_options = {}) ⇒ String
Renders the label of a content type entry.
-
#options_for_filter_fields(content_type) ⇒ Array
List the fields which could be used to filter the content entries in the back-office.
Instance Method Details
#entry_label(content_type, entry, location_options = {}) ⇒ String
Renders the label of a content type entry. If no entry_template filled in the content type, it just calls the _label method of the entry (based on the label_field_id). Otherwise, it parses and renders the liquid template.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/locomotive/content_types_helper.rb', line 13 def entry_label(content_type, entry, = {}) link = edit_content_entry_path(current_site, content_type.slug, entry, ) if content_type.entry_template.blank? label = entry._label(content_type).presence || t(:untranslated, scope: 'locomotive.shared.list') link_to label, link # default one else assigns = { 'site' => current_site, 'entry' => entry.to_liquid(content_type), 'link' => link, 'today' => Date.today, 'now' => Time.zone.now } registers = { site: current_site, locale: current_content_locale.to_s, services: Locomotive::Steam::Services.build_instance } context = ::Liquid::Context.new({}, assigns, registers) content_type.render_entry_template(context).html_safe end end |
#options_for_filter_fields(content_type) ⇒ Array
List the fields which could be used to filter the content entries in the back-office. Not all the types are included. Only: string, text, integer, float, email
36 37 38 39 40 41 |
# File 'app/helpers/locomotive/content_types_helper.rb', line 36 def (content_type) allowed_types = %w(string text integer float email) fields = content_type.entries_custom_fields.where(:type.in => allowed_types) fields.map { |field| [field.label, field._id] } end |