Introducting page variables defined earlier in a *.md file

Hello guys,

I need some help introducting page variables specified in a given post *.md file. I have to include a list of figures from a directory which changes by post (so as to organize the images better) and don’t want to type the full path in the image src attribute.

So I was thinking I could define a variable like imagedir = “/assets/images” at the top of the particular post. The image directory for this post will contains the images for that post.

My problem is that I don’t seem to be able to inject the variable correctly. For example I have used
and some other variants but it doesn’t render at all.

What is the correct way to introduce a variable defined in the post *.md file (at the top) subsequently in the document.


Use shortcodes.

Thanks bep. I will test that out.

What is the best format to be writing posts. I am using .md files but a quick of the Shortcodes section of the Hugo documentation says there are things Markdown doesn’t support well. Should/Could I be using another format. For now, I write in *.md with a bunch of front matter but also have to use html tags in the .md document.