class Liquid::Increment
@liquid_syntax_keyword variable_name The name of the variable being incremented.
{% increment variable_name %}
@liquid_syntax
variables.
and [‘capture`](/docs/api/liquid/tags/capture). However, `increment` and [`decrement`](/docs/api/liquid/tags/decrement) share
Similarly, variables that are created with `increment` are independent from those created with [`assign`](/docs/api/liquid/tags/assign)<br><br>(/themes/architecture#snippets) included in the file.
or [section](/themes/architecture/sections) file that they’re created in. However, the variable is shared across
Variables that are declared with ‘increment` are unique to the [layout](/themes/architecture/layouts), [template](/themes/architecture/templates),
@liquid_description
Creates a new variable, with a default value of 0, that’s increased by 1 with each subsequent call.
@liquid_summary
@liquid_name increment
@liquid_category variable
@liquid_type tag
@liquid_public_docs
def initialize(tag_name, markup, options)
def initialize(tag_name, markup, options) super @variable_name = markup.strip end
def render_to_output_buffer(context, output)
def render_to_output_buffer(context, output) counter_environment = context.environments.first value = counter_environment[@variable_name] || 0 counter_environment[@variable_name] = value + 1 output << value.to_s output end