2

I've used redactor's custom formatting option before, but now I can't get anything to work. Here's what my file currently looks like:

{
    "buttons": [
        "formatting",
        "bold",
        "italic",
        "lists",
        "link"
    ],
    "formatting": ["p","blockquote"],
    "formattingAdd": {
        "h2": {
            "title": "Heading",
            "args": ["h2"]
        },
        "h4": {
            "title": "Subheading",
            "args": ["h4"]
        },
        "caption": {
            "title": "Caption",
            "args": ["p", "class", "caption"]        
        }
    },
    "buttonsAdd": ["sup", "sub"],
    "linkNewTab": true
}

I have the "h2" and "h4" under "formattingAdd" because I wanted them to use custom titles.

The problem is, none of my custom formats are working. The "p" and "blockquote" from "formatting" are working properly, but the other three styles don't do anything. They appear in the list, but don't restyle the text in the editor, or create the elements in the output.

Is there something in the syntax I'm missing? I'm in Craft 3, with the redactor plugin updated to the latest version.

  • Andrea, did you get this working at all in Craft3? – erwinheiser Dec 18 '18 at 15:24
  • Yes, Andris' answer is correct, the syntax changed a little. The args should be expressed as an object instead of an array. – Andrea Hall Dec 19 '18 at 16:09
2

That syntax looks to be for Redactor 2. The latest versions of the redactor plugin (starting from 2.0) use Redactor 3. The syntax has changed slightly

| improve this answer | |
1

If you encounter an "Invalid Argument – yii\base\InvalidArgumentException Syntax error." while copy-pasting from the linked documentation, make sure each key and value has quotation marks around them (instead of apostrophes or nothing at all), e.g.:

Instead of this:

"red-p-add": {
    title: 'Red Paragraph',
    api: 'module.block.format',
    args: {
        'tag': 'p',
        'class': 'red-styled'
    }
},

Use this:

"red-p-add": {
    "title": "Red Paragraph",
    "api": "module.block.format",
    "args": {
        "tag": "p",
        "class": "red-styled"
    }
},
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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