Hello,
I am trying to do a replace on a character and replace it with a newline in a shortcode in which I have used getCSV. For instance if I have Cat*Dog, I want it to be:
Cat
Dog
I tried the following code with \n and \r but both just give a space not a line break.
{{ replace ( index $r 12) “*” “\n” }}
Am I missing something?
Tx.
Mark
This code:
{{ $input := "Cat*Dog" }}
{{ $input }}
{{ replace $input "*" "\n" }}
Gives me:
Cat*Dog
Cat
Dog
Hi zwbetz,
Strange, this does not work for me. I just get a space. If I replace the * with ^ it works, but not the newline.
???
Mark
I’m viewing the html file that hugo generates in a text editor, so I see the newline. If you’re looking at the html file through hugo server
and a web browser, then you probably want <br>
instead of \n
If I replace the \n with <br> I get:
Cat<br>Dog
Ah, because you need to pipe to safeHTML
. So to show all those combos again.
Template code:
{{ $input := "Cat*Dog" }}
{{ $input }}
{{ replace $input "*" "\n" }}
{{ replace $input "*" "<br>" }}
{{ replace $input "*" "<br>" | safeHTML }}
Text editor view:
Cat*Dog
Cat
Dog
Cat<br>Dog
Cat<br>Dog
Browser view:
Cat*Dog Cat Dog Cat<br>Dog Cat
Dog
Tx. very much. Now I know what safeHTML is for 