Shopify / Shopify/liquid

Is it possible to store a variable like in Capture but make it available everywhere in the parent scope?

Open
#1,199 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

How can I create a Block tag that behaves like a Capture tag, but I want it to be available anywhere in the calling template, not ONLY after it.

For example, the Capture tag looks like:

class Capture < Block
    Syntax = /(#{VariableSignature}+)/o

    def initialize(tag_name, markup, options)
      super
      if markup =~ Syntax
        @to = $1
      else
        raise SyntaxError.new(options[:locale].t("errors.syntax.capture"))
      end
    end

    def render(context)
      output = super
      context.scopes.last[@to] = output
      context.resource_limits.assign_score += output.length
      ''.freeze
    end

    def blank?
      true
    end
  end

And it currently works like:

{% capture heading %}
       Monkeys!
 {% endcapture %}
 
<h1>{{ heading }}</h1>

If you put {{heading}} before the definition of the variable, it doesn't work. Is it possible to make it work even BEFORE the definition? Somehow put the variable in the parent scope?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue provides a Capture implementation based on Block#render and context.scopes.last, but names no repository file or test. Start by tracing how Capture assigns its value and how template variable lookup handles scope and ordering; done requires a maintainer-approved design and coverage for the requested before-definition behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.