Presenting the same content chunks differently

With all the great help from Andy, I now understand how to reuse the same content on different pages within a Grav site.

Given that, I’d like to next present the same content differently on different pages. For example, given a list of youtube links on a markdown page might be displayed pretty much as-is on one page, but on another page use iframes to embed the videos on the page.

From what I understand, different Twig files for each page involved should be able to accomplish this. Is this correct, and is this the recommended approach to achieve the above?


That is correct, the page is the data and you can use different Twig templates to render that data in different ways. Don’t forget you are not limited to only the content of the page, you have the ability to set custom header options too.

Thanks very much for confirming that!

Are there any examples you could point me to showing different presentations of a list of links contained in a markdown file?

Thank you,

Not really. I can’t think of anywhere we’re doing this in our skeletons or demos. It’s just a matter of creating multiple twig files that have different rendering.

OK, I will start to learn more about Twig and see if I can get a working example going. Thanks again for all your help so far.

I now better understand that to use different content presentations I just need to have different twig files for the same markdown data. One example usage scenario for me is to have a markdown file contain a title and a short list of youtube links, and have one twig template render basically as-is, but have another twig template render each youtube video as an embedded video.

I’ve been looking for some example Twig code to process a markdown file for links, and for each link insert the found URL into a chunk of iframe code (i.e. to embed a YouTube video) but I’ve had no luck so far.

With the additional details above, would anyone know of an example I could review to learn how to possibly do this?

Thanks very much,

I would take a look at some of the modular skeleton packages and see how those were built. For example:

And it’s accompanying twig template for rendering:

This shows you how you can put things (like youtube links) into the header of a page, then iterate over them.

Awesome, this is very helpful Andy! I will review and see what I can come up with.

Thank you,