Skip to content

Commit

Permalink
Allow marks to use merge when using template-based config
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed May 28, 2021
1 parent d61f940 commit a338cb7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions docs/template-guides/modify-nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 4 additions & 1 deletion src/models/NodeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit a338cb7

Please sign in to comment.