Another option is to use the "capture" tag, which captures the string inside two tags, and then assigns the result to another (string) variable (see docs on Liquid variables for details). For an input integer variant.id
(following @fabio-filippi here) you'll end up with something like this:
{% capture variant_id %}{{ variant.id }}{% endcapture %}
Variable variant_id
is now the string representation of variant.id
. I personally think this is slightly more elegant than the other proposed solutions I've seen floating around the net. I'm still surprised Liquid doesn't have a built-in, dedicated tag for such a basic operation though.