diff --git a/docs/template-guides/modify-nodes.md b/docs/template-guides/modify-nodes.md index 8b69e09..92e761b 100644 --- a/docs/template-guides/modify-nodes.md +++ b/docs/template-guides/modify-nodes.md @@ -75,6 +75,23 @@ So far, all the overrides we've done have completely replaced the attributes on Importantly, the Paragraph node actually outputs a `text-left`, `text-right`, etc class depending on the alignment in the editor. Without `merge` set, our custom class would completely replace these clases, losing our alignment functionality. +You can also use `merge` for marks. + +```twig +{{ entry.vizyField.renderHtml({ + paragraph: { + marks: { + link: { + merge: true, + attrs: { + class: 'text-xl', + }, + }, + }, + }, +}) }} +``` + ## Using PHP Alternatively, you can use the PHP method from a plugin or module to control this behaviour as well. diff --git a/src/models/NodeCollection.php b/src/models/NodeCollection.php index b1e3a92..48a9e08 100644 --- a/src/models/NodeCollection.php +++ b/src/models/NodeCollection.php @@ -186,7 +186,10 @@ private function _prepNodesForHtml($config = []) $markConfig = $marksConfig[$mark->getType()] ?? []; if ($markConfig) { - Craft::configure($mark, $markConfig); + // Check if we want to merge attributes, instead of replace. Useful for attrs. + $merge = ArrayHelper::remove($markConfig, 'merge'); + + self::configure($mark, $markConfig, $merge); } } }