Skip to content

Commit a338cb7

Browse files
committed
Allow marks to use merge when using template-based config
1 parent d61f940 commit a338cb7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

docs/template-guides/modify-nodes.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ So far, all the overrides we've done have completely replaced the attributes on
7575

7676
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.
7777

78+
You can also use `merge` for marks.
79+
80+
```twig
81+
{{ entry.vizyField.renderHtml({
82+
paragraph: {
83+
marks: {
84+
link: {
85+
merge: true,
86+
attrs: {
87+
class: 'text-xl',
88+
},
89+
},
90+
},
91+
},
92+
}) }}
93+
```
94+
7895
## Using PHP
7996
Alternatively, you can use the PHP method from a plugin or module to control this behaviour as well.
8097

src/models/NodeCollection.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ private function _prepNodesForHtml($config = [])
186186
$markConfig = $marksConfig[$mark->getType()] ?? [];
187187

188188
if ($markConfig) {
189-
Craft::configure($mark, $markConfig);
189+
// Check if we want to merge attributes, instead of replace. Useful for attrs.
190+
$merge = ArrayHelper::remove($markConfig, 'merge');
191+
192+
self::configure($mark, $markConfig, $merge);
190193
}
191194
}
192195
}

0 commit comments

Comments
 (0)