How do I create small reusable HTML chunks with variables? #11359
Replies: 3 comments 13 replies
-
Partials are partials not whole templates. Possible solutions (all documented):
Note that to add links, there is native feature for that: https://quarto.org/docs/output-formats/html-basics.html#code-links-and-other-links (or https://quarto.org/docs/output-formats/html-multi-format.html if you generate the PDF from the same document) |
Beta Was this translation helpful? Give feedback.
-
If you could consider using computation engine for this, you can create a function in the chosen language to fill your HTML snippet template with desired content, and output for the cells or inline evaluation as raw content in the document. It would require R, Jupyter or Julia for your rendering, but it would definitely make this easy as the computation happens before any rendering to output. Example with R using glue for filling the snippet template
If you don't want engine, you may also probably leverage Pandoc Lua filter and the fact that Pandoc templating is available in Pandoc's Lua API: https://pandoc.org/lua-filters.html#module-pandoc.template So you have a template and fill it before inserting in the AST, while hiding this in a shortcode just an idea I need to experiment with though 😅 |
Beta Was this translation helpful? Give feedback.
-
@tim-at-topos I made a shortcode extension that works like this called partials and it's specifically designed to let you do something like this: {{< partial _button.qmd link="https://example.com" text="Example button" >}} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I am writing a website in Quarto, and I really like being able to keep the contents as
.qmd
files because these are nice and simple to read and edit — I can give users access to these to make content edits without them having to worry about HTML elements.However, there are a few HTML snippets that repeat often. For example, whenever I have a button linking to a PDF, I write this in HTML as
I would like to be able to turn this into a partial/template (or whatever the correct terminology is here) so that I can simply write something like
include(pdf_link, $LINK, $LINK_TEXT)
in my.qmd
files, and make changes to thepdf_link
snippet to change all such buttons globally.I'm sure this is supported somehow, and is maybe even a Pandoc feature instead of a Quarto one, but I can't find any links to this in the docs (I've tried searching for "partial", "template", and "EJS" but these all seem to just concern writing templates for entires pages instead of snippets, and "snippets" just gives me information about rendering syntax-highlighted code snippets).
Beta Was this translation helpful? Give feedback.
All reactions