AlchemyCMS / alchemy_cms

Alchemy is the Open Source Rails CMS framework for the component based web that can be used as classic server side rendered or headless CMS.
https://www.alchemy-cms.com
BSD 3-Clause "New" or "Revised" License
845 stars 314 forks source link

EssenceLink - Renderer - Show URL instead of Link Title #1492

Closed aaongr closed 5 years ago

aaongr commented 6 years ago

Steps to reproduce

Create an EssenceLink and fill in the URL, Link Title and open in new window

Expected behavior

The Link Title should be shown in the preview window

Actual behavior

The URL show in the preview window as a link

Elements.yml

- name: entity
  hint: true
  contents:
  - name: title_text
    type: EssenceText
    hint: true
  - name: picture
    type: EssencePicture
    hint: true
  - name: multi_line_text
    type: EssenceMarkdown
    hint: true
  nestable_elements:
    - link_nested
    - attachment_nested

- name: link_nested
  contents:
    - name: link
      type: EssenceLink
      hint: true

app/views/alchemy/elements/_link_nested_view.html.erb

<%- cache(element) do -%>
  <%= element_view_for(element) do |el| -%>
    <%= el.render :link %>
  <%- end -%>
<%- end -%>
tvdeyen commented 6 years ago

The link is displayed only if you do not set text as content settings.

https://github.com/AlchemyCMS/alchemy_cms/blob/b6d8ceacd2ac1faa4a58b303194eaad079f1e9dc/app/views/alchemy/essences/_essence_link_view.html.erb#L6-L7

- name: link_nested
  contents:
    - name: link
      type: EssenceLink
      hint: true
      settings:
        text: My link text

The Alchemy::EssenceLink#link_title is meant as the title attribute on the <a> tag created. But currently not used in the essence partial I just saw. This should be fixed actually.

What you may also want to use is an EssenceText with the linkable: true attribute. That way the content editor can enter the text of the link in the text field.

- name: link_nested
  contents:
    - name: link
      type: EssenceText
      hint: true
      settings:
        linkable: true
tvdeyen commented 6 years ago

Probably something we should mention in the guides.

alexanderadam commented 5 years ago

IMHO absolutely related:

Is it correct that Alchemy::EssenceLink#link_title is not used in _essence_link_view.html.erb or am I missing something?

It seems that only settings/text: Foo or content.ingredient (which is basically the link) is shown. I would have expected something like

content.essence&.link_title.presence || content.settings_value(:text, local_assigns.fetch(:options, {})) || content.ingredient