I’ve tried to set a variable (using if isset based logic), but no matter what I do, it comes back with an undefined variable error.
Any advise on what to go learn to make this better would be greatly appreciated.
As a bonus question, I have a html linter installed with VSCode that formats the code on save. It freaks out with the handlebars syntax, especially in <style> ... </style> tags. Anyone know a way around that besides turning the linter off?
@binaryben I haven’t had a chance to try it out, but try putting the stuff within the style tags in a partial and put {{ partial "that_new_partial.css" . | safeCSS }} between those style tags… should work… (or at least work more than now :))
Thanks @kaushalmodi. Just to be clear, the code I copied above is working. But it’s very long and easy to break (I’m expecting students to be working on this project).
What I would normally expect to be able to do is something like this:
<style>
{{range $index, $element := .Site.Params.social}}{{if isset $element "colour"}}
<!-- borrowing from javascript's syntax to get my point across -->
{{ $icon := (isset $element "icon") ? $element.icon : $index }}
.social-icons .fa-{{- $icon -}}:before {
color: {{ $element.colour }} !important;
}
{{ end }}{{ end }}
</style>
<div id="uwacore-footer-extras">
... (same mechanism again) ...
</div>
But no matter how I try to assign a value to the $icon variable, I always get the undefined variable error when I try to build the site. So is there a “proper” way I should be doing this?
Does anyone have an answer for a linting plugin for VSCode that doesn’t freak out with handlebars in a html file? It especially struggles with the handlebars being used in tags.
That works for HTML in a document, but unfortunately no longer lints CSS within <style> tags of a document. Maybe I need specifically need a seperate CSS and JS linter as well that supports handlebars… I keep trying to use variables in all types of code.