[SOLVED] Custom srcset shortcode inside layout-files (html)


I’m currently implementing srcset attributes for all images in of my Hugo sites and I would like to use something like a function or shortcode which gets a few variables and outputs the HTML srcset code.

My first try was using the Hugo shortcodes, but unfortunately they are only working in content-files and not in layout-files. The next one was using partials, but they can’t access multiple paramaters.

Has anyone build something similar or is there a way to use shortcodes in layout-files?

Thanks :slightly_smiling:

This is based on Jekyll but you should be able to transfer to Hugo: Responsive Images with srcset.

You only have to change the variables and if-statements.

1 Like

Have a look at the dict func.

1 Like

Big thanks to both of you, exactly what I’ve searched for.