Edinburgh-Genome-Foundry / blabel

:label: Python label/sticker PDF generation. HTML templates, built-in barcodes, qr codes, and other goodies
https://edinburgh-genome-foundry.github.io/blabel
MIT License
179 stars 38 forks source link

Putting multiple elements into QR code #17

Closed rickmedlin closed 2 years ago

rickmedlin commented 2 years ago

The more I use this package, the more I like it. However I would like to put multiple elements in the QR code.

I've tried these ways without success in the Jinja / image template:

<img src="{{label_tools.qr_code(element_1, element_2, element_3)}}" />

<img src="{{label_tools.qr_code(element_1)}} {{label_tools.qr_code(element_2)}} {{label_tools.qr_code(element_3)}}" />

Is this possible?

rickmedlin commented 2 years ago

Never mind, A little research showed that one solution is the ~ operator:

<img src="{{label_tools.qr_code(element_1 ~ element_2 ~ element_3)}}" />

Zulko commented 2 years ago

Oh wow that sounds fancy, can you explain what it does?

rickmedlin commented 2 years ago

Not really fancy. As shown above, if you want to join multiple values inside a 'qr_code' statement, concatenate them with a '~'.

veghp commented 2 years ago

I leave this here for future reference: https://jinja.palletsprojects.com/en/3.0.x/templates/#other-operators

~ (tilde)
    Converts all operands into strings and concatenates them.
    {{ "Hello " ~ name ~ "!" }} would return (assuming name is set to 'John') Hello John!.