Login  Register

Conditionally setting image in Header in PDF

Posted by Patrick Ben Koetter on Nov 18, 2019; 9:29pm
URL: https://discuss.asciidoctor.org/Conditionally-setting-image-in-Header-in-PDF-tp7356.html

Greetings,

I'm looking for an elegant way to set which image to use in PDF headers
(running content) to indicate which classification a document has.

The simpliest, but not so elegant way I can think of is to specify a dedicated
theme, which sets the correct header like along this concept:

# theme 1
header:
    ...
        recto:
            right:
                content: image:../assets/level1.png[]
        verso:
            left:
                content: $header-recto-right-content

# theme 2
header:
    ...
        recto:
            right:
                content: image:../assets/level2.png[]
        verso:
            left:
                content: $header-recto-right-content

But that will create lots of reduncancy in the themes and only the image would
change with the classification.

Ideally I would set the classification as VAR in the document:

= My Document
:classification: level1
...

And then $SOMETHING would evaluate the condition and set the image associated
with the {classification}.

I thought a simple attribute reference
<https://github.com/asciidoctor/asciidoctor-pdf/blob/master/docs/theming-guide.adoc#attribute-references>
might work, but it won't if I do it like this:

= My Document
:classification: level1
...

header:
    ...
        recto:
            right:
                content: image:../assets/{classification}.png[]
        verso:
            left:
                content: $header-recto-right-content

However if I specify the image name as attribute, the image isn't embedded
whereas if I hardcode it, it will be.

Any ideas what I am doing wrong or a different way to do it?


TIA,

p@rick


--
[*] sys4 AG
 
https://sys4.de, +49 (89) 30 90 46 64
Schleißheimer Straße 26/MG,80333 München
 
Sitz der Gesellschaft: München, Amtsgericht München: HRB 199263
Vorstand: Patrick Ben Koetter, Marc Schiffbauer, Wolfgang Stief
Aufsichtsratsvorsitzender: Florian Kirstein