Search code examples
quarto

How to insert a date string in a paragraph in Quarto


I'm new to Quarto for document generation and want to insert a date string. I understand that one can add it to the YAML header at the beginning of the file, but this puts the date in a pre-designated spot. I want to insert a date (i.e. "10/11/22") within a paragraph later in the text. Is there a way to insert "fields" or variables within text? Thanks.


Solution

  • You can use the meta shortcode. The meta shortcode allows you to insert content from Pandoc metadata (e.g. YAML fields at the top of the document)

    So to use the date field from YAML metadata, use {{< meta date >}} in the paragraph or anywhere you want to use the date meta data.

    ---
    title: "Document metadata"
    format: html
    date: "10/11/22"
    date-format: "DD/MM/YY"
    ---
    
    ## Quarto
    
    This document was published at {{< meta date >}}
    
    

    And Quarto supports a varying way of date formatting, see Quarto Dates and Date Formatting from the docs.


    adding meta data in the document