[SOLVED] Getting garbage when setting HTML style attribute via .Params

I’ve been working on templates to list summaries on an index page. What I would like to implement is the ability to style a summary block from the actual content, i.e. via page .Params.featurestyle:

Content file:

title = "Test Title"
date = "2017-11-03T18:10:10+11:00"
description = "Meow foobar."
featurestyle = "color: green; background: red;"

Template list.html file that lists the summaries:

{{ $pageList := where .Site.Home.Pages "Section" "projects" }}

{{ range $page := $pageList }}

	<section class="feature" style="{{ $page.Params.featurestyle }}">
		<a class="blockAnchor" href="{{ $page.Permalink }}">
			<h2>{{ $page.Title }}</h2>
		 	<aside>{{ $page.Summary }}</aside>
{{ end }}

The issue is with the following line:

<section class="feature" style="{{ $page.Params.featurestyle }}">

The output should be:

<section class="feature" style="color: green; background: red;">

Instead I’m getting:

<section class="feature" style="ZgotmplZ">

Bug, or am I doing something wrong?

It is always a good idea to search for the error you get. :stuck_out_tongue:

Pass your parameter through safeCSS.

1 Like

Ah awesome. I was poking around with safeHTML but haven’t realised safeCSS was a thing. Thanks for the tip.