Custom field for camaleon cms internal link

Camaleon CMS gem is a Wordpress alternative built in Ruby on Rails 4.  It's well expandable. Below you can find an easy example of a custom field.

Firstly in file "app/apps/themes/my_theme/config/config.json" add

"hooks": {

....

"extra_custom_fields": ["my_theme_extra_custom_fields"]

main_helper.rb in "app/apps/themes/my_theme/"

def my_theme_extra_custom_fields(args)

args[:fields][:page_picker] = {

key: 'page_picker',

label: 'Internal link',

render: theme_view('custom_field/page_picker.html.erb'),

options: {

required: false,

multiple: false,

}

}

end

Create partial with your select internal link tag "app/apps/themes/my_theme/views/custom_field/_page_picker.html.erb"

<div class="group-input-fields-content">

<%= select_tag "#{field_name}[#{field.slug}][values][]", options_from_collection_for_select(@current_site.the_posts.decorate, "the_url", "the_url"), class: "form-control input-value #{"required" if field.options[:required].to_s.to_bool}", include_blank: true %>

</div>

And that's all folks. In a few simple steps you can build your own custom field with internal link picker.