CMS Development

SirHubalot
Membre

Unable To Remove Whitespace From Macro Value

Résolue

I'm trying to return a value from a macro without any whitespace. From the documentation, I've tried to use the "-" within the start and end block of the macro declaration that doesn't seem to do anything.

 

{% macro domainToLangCodeMap() -%}
{% set domain_extension = content.absolute_url|replace("https://", "")|replace("http://", "")|split('/')|first|split('.')|last %}
{% set content_two_letter_language_code = content.language.languageTag|split('-')|first %}

{% if domain_extension == "be" or domain_extension == "nl" %}
{{content_two_letter_language_code}}
{% elif domain_extension == "se" %}
{{"sw"}}
{% elif domain_extension == "dk" %}
{{"da"}}
{% else %}
{{domain_extension}}
{% endif %}
{%- endmacro %}

When I output the macro to the page, there is whitespace surrounding the value which is stopping me passing it to one of my module choice fields.

 

Is there anything I've missed?

0 Votes
1 Solution acceptée
Kevin-C
Solution
Expert reconnu | Partenaire solutions
Expert reconnu | Partenaire solutions

Unable To Remove Whitespace From Macro Value

Résolue

@SirHubalot Could you post a screenshot of the output you're getting and the html it generates and what you're expecting it to look like?

 

To add to @Anton 's answer, you might combine |trim with |render when passing the value to the module.

Kevin Cornett - Sr. Solutions Architect @ BridgeRev

Voir la solution dans l'envoi d'origine

4 Réponses
Kevin-C
Solution
Expert reconnu | Partenaire solutions
Expert reconnu | Partenaire solutions

Unable To Remove Whitespace From Macro Value

Résolue

@SirHubalot Could you post a screenshot of the output you're getting and the html it generates and what you're expecting it to look like?

 

To add to @Anton 's answer, you might combine |trim with |render when passing the value to the module.

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
SirHubalot
Membre

Unable To Remove Whitespace From Macro Value

Résolue

@Kevin-CAh yes, the addition of the render filter did the job. I hope there will be a fix in the future where a macro by default will remove any whitespace.

0 Votes
Anton
Expert reconnu | Partenaire solutions Diamond
Expert reconnu | Partenaire solutions Diamond

Unable To Remove Whitespace From Macro Value

Résolue

Hi @SirHubalot

 

have you tried to trim the value?

 

 

best, 

Anton

Anton Bujanowski Signature
SirHubalot
Membre

Unable To Remove Whitespace From Macro Value

Résolue

Hi @Anton , I did and that didn't change the output at all.

0 Votes