Whitespace issue with custom Bard logic #11304
-
I use a custom loop to build my own Bard rendering logic. This allows me to render partials for parts of Bard text: {{ foreach :array="bard|raw" }}
{{ if value:type == 'heading' }}
{{ switch(
(value:attrs:level == '2') => { partial:typography/heading :heading="value:content:0:text" },
(value:attrs:level == '3') => { partial:typography/heading as="h3" :heading="value:content:0:text" },
(value:attrs:level == '4') => { partial:typography/heading as="h4" :heading="value:content:0:text" },
() => { text }
) }}
{{ elseif value:type == 'paragraph' }}
<p
{{ value:attrs:class ?= 'class="{value:attrs:class}"' }}
{{ value:attrs:textAlign == 'left' ? '' : 'style="text-align: {value:attrs:textAlign}"' }}
>
{{ partial:typography/paragraph :content="value:content" }}
</p>
{{ elseif value:type == 'bulletList' }}
<ul>
{{ value:content }}
<li>
{{ partial:typography/paragraph :content="content:0:content" }}
</li>
{{ /value:content }}
</ul>
{{ /if }}
{{ /foreach }} The paragraph partial: {{ content }}
{{ if type == 'hardBreak' }}
<br>
{{ elseif marks }}
{{ if marks:0:type == 'bold' }}
<strong>{{ text }}</strong>
{{ elseif marks:0:type == 'link' }}
{{ href = marks:0:attrs:href|explode('::')|last }}
{{ url = href|url }}
<a
href="{{ url ? url : href }}"
{{ marks:0:attrs:rel ?= 'rel="{marks:0:rel}"' }}
{{ marks:0:attrs:target ?= 'target="{marks:0:target}"' }}
{{ marks:0:attrs:title ?= 'title="{marks:0:title}"' }}
class="inline-block"
>{{ text|antlers }}</a>
{{ /if }}
{{ else }}
{{ text|antlers }}
{{ /if }}
{{ /content }} Works great so far, but I have a little nasty issue with punctuation that immediately follows a link in the paragraph partial. There is a whitespace between the two: Because of the loop, the dot is placed on a new line in the HTML output and the browser renders a space. I know there is a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Why can't you use it with the spaceless modifier? |
Beta Was this translation helpful? Give feedback.
{{ { partia:...... } | spaceless }}