Changing shortcode behaviour depending the layout

Hi,

I have a shortcode named “image” that generates thumbnails with .Resize Hugo function.

I made a layout called pdfgenerator that displays all the pages of the website so I can print a pdf with the whole content of my website.

What I want is that all my “image” shortcodes don’t generate thumbnails ONLY in the pdfgenerator layout.

I tried everything including setting .Page.Scratch from the pdfgenerator layout or trying to get front-matter params of the page (pdfgenerator) from the sub-pages (all my posts). Nothing works. Is there a way to pass a param to a shortcode from the layout context ? Or maybe to load a different shortcode for a specific layout ?

Thanks for your help.

The main problem is that we render the content (including shortcodes) once.

We do support shortcodes per outputformat and language, so what I would suggest is that you, instead of creating a PDF layout, create a PDF output format (or whatever). Then you can have:

  • myshortcode.html
  • myshortcode.pdf.html

It’s Friday night, so I’m not totally sure of the naming rules etc., but it should be documented.

I will try this, thanks bep :slight_smile:

EDIT : works like a charm

1 Like