2

How do I concatenate a value in a Jinja template? I tried the following but the value is rendered separately from the attribute.

<input type="button" id="button" + {{ entry.id }}>
1
  • 6
    id="button{{ entry.id }}" Commented Jul 22, 2016 at 16:00

1 Answer 1

13

Look at the output of your current template: id="button" + 3. Anything outside of {{ }} isn't interpreted by Jinja, it's just treated as text.

Either put the expression right next to the text, or put the string inside the expression.

id="button{{ entry.id }}"
or
id="{{ "button" ~ entry.id }}"

The ~ is a special Jinja operator that does concatenation (like +), but converts each side to a string first.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.