<p>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 <a href="https://imperavi.com/redactor/docs/settings/formatting/#s-formattingadd" rel="nofollow noreferrer">changed slightly</a></p>

CC BY-SA 4.0
2018-10-26T11:16:33.027Z
2018-10-26T11:16:33.027Z
Andris Sevcenko
<p>If you encounter an "Invalid Argument – yii\base\InvalidArgumentException Syntax error." while copy-pasting from the <a href="https://imperavi.com/redactor/docs/settings/formatting/#s-formattingadd" rel="nofollow noreferrer">linked documentation</a>, make sure each key and value has quotation marks around them (instead of apostrophes or nothing at all), e.g.: </p>

<p>Instead of this: </p>

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

<p>Use this: </p>

<pre><code>"red-p-add": {
    "title": "Red Paragraph",
    "api": "module.block.format",
    "args": {
        "tag": "p",
        "class": "red-styled"
    }
},
</code></pre>

CC BY-SA 4.0
2021-02-11T13:36:55.133Z
Thanks, this helped me too.
Masiorama
CC BY-SA 4.0
2020-01-06T15:28:36.840Z
2020-01-06T15:28:36.840Z
Ottó Radics
<p>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:</p>

<pre><code>{
    "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
}
</code></pre>

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

<p>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. </p>

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

CC BY-SA 4.0
2018-12-18T15:24:35.793Z
Andrea, did you get this working at all in Craft3?
erwinheiser
CC BY-SA 4.0
2018-12-19T16:09:39.213Z
Yes, Andris' answer is correct, the syntax changed a little. The args should be expressed as an object instead of an array.
Andrea Hall
<craft3><redactor>
Redactor formattingAdd not working
# Redactor formattingAdd not working

(Asked by: username_0 on 2018-10-25)

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.

**Tags:** craft3, redactor

> **Comments:**
> **username_1**: Andrea, did you get this working at all in Craft3?  
> **username_0**: Yes, Andris' answer is correct, the syntax changed a little. The args should be expressed as an object instead of an array.  

---

## 2 answers

### Answer by username_2 on 2018-10-26. Score: 3 | Accepted answer

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](https://imperavi.com/redactor/docs/settings/formatting/#s-formattingadd)


---

### Answer by username_3 on 2020-01-06. Score: 4

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"
    }
},

> **Comments:**
> **username_4**: Thanks, this helped me too.  

---

