-
Notifications
You must be signed in to change notification settings - Fork 9
Attr
Attr is a powerful filter which enables you to add, add to, replace or remove attributes for one or more selectors.
Set class for all p tags (will remove any existing classes)
{{ entry.body | retconAttr( 'p', { 'class' : 'someClass' } ) }}
Add a class for all p tags (will not remove any existing classes)
{{ entry.body | retconAttr( 'p', { 'class' : 'someClass' }, false ) }}
Add a class to several selectors at once
{{ entry.body | retconAttr( [ '.foo', '.bar' ], { 'class' : 'someClass' } ) }}
Remove inline styles for all elements
{{ entry.body | retconAttr( '*', { 'style' : false } ) }}
Add multiple attributes
{{ entry.body | retconAttr( '.foo', { 'class' : 'bar', 'data-baz' : 'qux' } ) }}
Add an attribute without a value
{{ entry.body | retconAttr( 'script', { 'async' : true } ) }}
Remove attributes
{{ entry.body | retconAttr( 'img', { 'width' : false, 'height' : false } ) }}
@selectors Mixed
String value or Array of string values
Examples: "p"
".foo"
"#bar"
"div.baz"
@attributes Array
Associative Array of attributes and attribute values.
Tip: Set attribute value to false
or null
to remove the attribute.
@overwrite Boolean
Optional, default true
If true
, any existing attribute values will be replaced. If false
, attribute values will be added.