Inserting Additional HTML to RSS/JSON feeds

Hello,

I am sure there is a simple explanation to this, but I can’t find it.

Given the following setup in my JSON feed template:

"content_html": {{ $element.Content | jsonify }},

I’m trying to append additional HTML to $element.Content based on a flag in the front matter:

{{ if isset $element.Params "link" }}
"content_html": {{ $element.Content | jsonify }}, // append HTML here
{{ else }}
"content_html": {{ $element.Content | jsonify }},
{{ end }}

I’m not sure of the best way to go about it. I’ve tried using readFile to read the HTML from a local file, but it throws an error saying it’s expecting a string but is instead getting a template.HTML file.

Any advice on the best way to go about this?

{{ printf "%s" $variable }} will make your template.HTML into a string.

Without more info, I am not sure how to answer the “proper way” part of the question. If it works keep it that way.

“Appending” could be done via this:

{{ printf "%s%s" $variable1 $variable2 }}

So, maybe, untested, like this:

{{ $content := $element.Content }}
{{ if isset $element.Params "link" }}
{{ $content = printf "%s%s" $element.Content $theVariableWithYourHTML }}
{{ end }}
"content_html": {{ $content }}

sometime helps to look in a sample

It’s a working JSON feed.