Something like shortcodes in layouts?

@bryankang I’m not certain at what you’re looking for, but I’m a big fan of Tachyons. Here are a few things I do with them (which are not specific to Tachyons, but are beneficial to using them):


One: Assign sets of classes in a data file or config. Arguably, you could do this with a post-processing workflow, but I find this is simple and flexibile:

For example, in data/globals.yaml or in your config:

box_styles: "bg-white gray mb3 ph4 pv3"

and in a template, something like:
{{.Site.Data.globals.box_styles}}


Two: Assign class names through the dict function in a partial:

In a partial (I often create a folder in my partials called “components” and put stuff like this in it):

/component/component.html

<div class="{{with .classes}}{{.}}{{end}}">
	//stuff
</div>

In your template:

{{partial "components/component.html" (dict "classes" "bg-white gray mb3 ph4 pv3") }}


Of course, you can create simple variables with class names to reuse them, or whatever works best for you. Overall, the combination of Hugo and Tachyons makes for an extremely efficient workflow. Hope that helps!

4 Likes