Link list

97 views
Skip to first unread message

Marc

unread,
May 22, 2012, 8:27:53 PM5/22/12
to alche...@googlegroups.com
Hey there,

I want to implement a link list, very easy: a headline and a bunch of text-links in an unordered list.

My thoughts so far: element names link_list, essenceText 'headline' and essenceText 'link'.
It should be possible to make the link :linkable, at least it is mentioned in the associated editor-partial.

But there are also a few questions left:
- Implementation should be like picture_editor, but I'd like to have more than one content at the beginning. 
  Do I have to create all the contents at the beginning or is there a better way? What about adding new fields on demand?
- How to render the linkable-button? Everywhere else it's like options[:linkable], but in that partial it's content.settings[:linkable]. I mean, when I use render_essence_editor_by_name I don't have access to content directly!

Regards
Marc

Thomas von Deyen

unread,
May 23, 2012, 4:09:54 AM5/23/12
to alche...@googlegroups.com
Hi Marc.

This is possible.

1. Linkable Setting

In your elements.yml you can add linkable: true to your EssenceText settings hash key.

Example:

# elements.yml
- name: link_list
contents:
- name: headline
type: EssenceText
- name: link_1
type: EssenceText
settings:
linkable: true

2. Additional Contents

You can declare a list of contents on your element that can be added on demand.
You just need to add a available_content array.
The DSL is the same as for the contents collection.

Example:

# elements.yml
- name: link_list
contents:
- name: headline
type: EssenceText
- name: link_1
type: EssenceText
settings:
linkable: true
available_contents:
- name: link
type: EssenceText
settings:
linkable: true

Then you can add one of this two helpers to your elements editor view:

1. render_new_content_link(element) (http://rubydoc.info/github/magiclabs/alchemy_cms/Alchemy/Admin/ContentsHelper#render_new_content_link-instance_method)
This one opens an overlay with a selectbox of available contents the user can choose from

2. render_create_content_link(element, :content_name => 'link') (http://rubydoc.info/github/magiclabs/alchemy_cms/Alchemy/Admin/ContentsHelper#render_create_content_link-instance_method)
This directly creates the content.


This should be it.

Best


Thomas von Deyen
magic labs*

Marc

unread,
May 23, 2012, 6:42:11 AM5/23/12
to alche...@googlegroups.com
Toooo easy ;-)

Up and running in 10 minutes...

One last thing:
I had to change _essence_text_view in order to catch a nil-error:
<%- if content.essence.link.blank? || (options and options[:disable_link]) -%>

when called via  render_essence(content). Did you have this before?

Regards
Marc

Seems like options isn't available if called with 
Message has been deleted

Thomas von Deyen

unread,
Jul 12, 2013, 2:32:39 AM7/12/13
to alche...@googlegroups.com
I assume with additional content you mean the other attributes of the essence.

Using the render_essence_* helpers Alchemy returns the attribute set as ingredient_column on the acts_as_essence definition in the model.

You can access the other attributes with classic OOP:

In the views you have the element object as local variable. The element model has some handy shortcuts to get the contents (and therefore essences) related to it:

all_contents_by_name
all_contents_by_type
content_by_name
content_by_type

To get the actual essence instance, you have to call

essence

on the content instance. Then call the attribute getter method.

Example:

element.content_by_name('headline').essence.link_class_name

Example 2:

element.contents_by_type('EssencePicture').each do |content|
content.essence.caption
end

Hope this helps


Thomas
Reply all
Reply to author
Forward
0 new messages