Topic on Extension talk:Variables

{{#vardefineecho:n|{{#expr:{{#var:n}}+1}}}}

8
Summary by MGChecker

This has been resolved with T191574.

Cavila (talkcontribs)

I recently advised someone to use this in a template but I was wrong: multiple instances of such a template will print a series of 1, 1, 1, 1, etc., while use of the same syntax without a template will give you a series of 1, 2, 3, 4, etc. Is this intended behaviour?

92.21.226.2 (talkcontribs)

If you repeatedly call a template without parameters, it will reuse the output of the first call. To make sure the template is evaluated each time you need to add an empty parameter: {{template|}}.

Cavila (talkcontribs)

Great, that should do it - thanks for this!

DavidBiesack (talkcontribs)

Ouch! This makes using variables and templates much more difficult. Is there some way to bypass the cache behavior so the template is expanded every time?

Danwe (talkcontribs)

When I last worked on the extension this didn't seem possible if I remember correctly. Or it was more effort than I thought was justified to solve this.

Just call the template with an empty parameter as pointed out above.

MGChecker (talkcontribs)

This is tracked in T191574 and hopefully fixed soon.

Gunnar.offel (talkcontribs)

So theres still no easy way to increment the variable to count anything?

MGChecker (talkcontribs)

There is. This is resolved in Variables 2.4+, which has been released in 2018.