1

I realise this is very much a Redactor question, but was wondering if anyone has figured out how to apply custom classes to UL's and OL's in Craft using the formattingAdd options?

I've tried the following but it just won't apply to any unordered lists I create:

{ tag: 'ul', title: 'Large list', class: 'large' }

1 Answer 1

2

This doesn’t appear to be possible without a plugin. The formattingAdd will add additional options to the Formatting menu, but will not alter the behavior of any of the other buttons, and you can only set the tag properties to p, pre, blockquote, and h[1-6].

Another option might be to use a Matrix field with two block types: Text and List. Text blocks would have a Rich Text field, and List blocks would have a Table field with one column, plus a Dropdown field that specifies what the class should be. From your templates you would do this:

{% for block in entry.myMatrixField %}
    {% if block.type == 'text' %}
        {{ block.text }}
    {% elseif block.type == 'list' %}
        <ul class="{{ block.myDropdownField }}">
            {% for row in block.myTableField %}
                <li>{{ row.myColumnHandle }}</li>
            {% endfor %}
        </ul>
    {% endif %}
{% endfor %}

If you really want to keep all this within Redactor and go the plugin route, you can use our Redactor Clips plugin as a starting point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.