I've found a similar question on StackOverflow, but the solution doesn't seem to work for me, unless I'm doing it wrong. I have a ID number, which I'd like to append to a string in a template tag. Here's my attempt:
{% with "image-"|add:vid.the_id as image_id %}
{# custom template tag to generate image #}
{% image vid.teaser_thumbnail alt=vid.title id=image_id %}
{% endwith %}
But image_id
is coming out as empty.
What am I doing wrong here?
My desired output of image_id
would be something like "image-8989723123".
Try this way (added with
statement with stringformat on top of yours):
{% with vid.the_id|stringformat:"s" as vid_id %}
{% with "image-"|add:vid_id as image_id %}
{# custom template tag to generate image #}
{% image vid.teaser_thumbnail alt=vid.title id=image_id %}
{% endwith %}
{% endwith %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With