Shopify / Shopify/liquid

Render specific partial

Open
#996 1 comment 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

I'm trying to do a tag that render a specific partial:

render(partial: "user/subscriptions/subscribable_box",
            locals: { subscribable: context.environments.first['current_site'],
                          title: I18n.t("gsubscribable_box.title") })

but I can't because I don't have registers in the controller and I'm trying to execute context.render...

# frozen_string_literal: true

class RenderSubscribableBox < Liquid::Tag
  def initialize(tag_name, params, tokens)
    super
  end

  def render(context)
    context.render(partial: "user/subscriptions/subscribable_box", locals: { subscribable: context.environments.first['current_site'], title: I18n.t("gsubscribable_box.title") })
  end
end

Liquid::Template.register_tag("render_subscribable_box", RenderSubscribableBox)

I tried the:

context.registers[:controller].render(partial: "user/subscriptions/subscribable_box", locals: { subscribable: context.environments.first['current_site'], title: I18n.t("subscribable_box.title") })

but it gives me back:

*** NoMethodError Exception: undefined method render' for nil:NilClass
`

How can I create a tag for a specific partial?

Thanks a lot

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

Start by tracing how the custom Liquid::Tag receives its context and how context.registers is populated during rendering. Investigate the render(context) method and the attempted context.registers[:controller] access; done means establishing whether a tag can render the requested partial or documenting the supported approach.

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.