Concatenate file paths with absURL

I am trying to create a versioned URL for my stylesheet. The version number is defined in config.toml.

{{ $path := "assets/css/theme-" . $.Site.Params.version . ".css"}}
<link rel="stylesheet" href="{{ $path | absURL }}">

Hugo fails with

ERROR 2018/01/17 16:26:58 Error while rendering "home" in "": template: layouts/index.html:14:16: executing "layouts/index.html" at <"assets/css/theme-">: can't give argument to non-function "assets/css/theme-"

What would be the correct way to create the url before adding it to the HTML?

Using + instead of . in the path creation fails with not a number errors by the way.

Try something ala

{ $path := printf “assets/css/theme-%s.css” $.Site.Params.version }}

2 Likes

Wow. Thank you. I actually tried something like that found here on the forum, but misread the error message. The forum software creates “stylized” quotes and copy paste breaks of course. Once I exchanged for “normal” quotes it did what was expected.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.