Skip to content

Accessing the template block when using Phlex::DeferredRender #571

Answered by joeldrapper
stex asked this question in Help
Discussion options

You must be logged in to vote

Hey @stex, we decided against passing the block to the template method when using deferred render because it could likely lead to confusing interfaces. Take this for example:

render Card.new do |c|
  p { "Before" }
  c.title { "Hello" }
  p { "After" }
end

If the card was implemented in the "builder style" like this, you would get the expected output.

class Card < Phlex::HTML
  def template(&)
    article(&)
  end

  def title(&)
    h1(class: "title", &)
  end
end

But if the card was implemented with deferred render, both paragraphs would appear after the title.

class Card < Phlex::HTML
  include Phlex::DeferredRender

  def template
    article do
      h1(class: "title", &@title)
      y…

Replies: 1 comment 12 replies

Comment options

You must be logged in to vote
12 replies
@willcosgrove
Comment options

@joeldrapper
Comment options

@willcosgrove
Comment options

@stex
Comment options

@stex
Comment options

Answer selected by stex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants