htmlruby-on-railshtml-listsalchemy-cms

How to make an Alchemy CMS element produce an HTML list


I'm trying to create an Alchemy CMS element which will produce an HTML list as its result. The element in question is a navigation bar that I want to be structured as a list in HTML because that is what the CSS which I have wants to work with. E.g., I'd like to have an element specified like so in config/alchemy/elements.yml:

- name: navbar
  unique: false
  nestable_elements: [navitem]
  contents:
  - name: logo # There's also a logo in this navbar
    type: EssencePicture

- name: navitem
  contents:
    - name: navitem_content
      type: EssenceText
      settings:
        linkable: true

And then have this navbar element become an <li> in the actual HTML which is generated. Unfortunately, this sort of thing doesn't yet work for me because the navbar that is generated (which encapsulates the logo and the navigation items) is actually a <div>. I'm not really sure how to change a given Alchemy element to be of a type other than a <div> (obviously, in this case, I want it to be an <li>).

The only thing I've seen thus far that might work for doing what I want is to create an Essence with the type of EssenceHtml. However, I don't think that this will be sufficient since I'm trying to nest other elements / Essences inside of this one (which I don't think works for Essences) and this just seems to emit static, raw HTML.

So, I guess I'm asking what the best way is to create an Alchemy element with the tag type that I want (in this case, an <li>), which will also contain other elements.


Solution

  • According to the documentation element_view_for helper has a tag option.

    Just pass tag: 'li' and you're all good.