Skip to content

unsafe_raw with yield renders the yielded content outside #793

Discussion options

You must be logged in to vote

That’s because this

unsafe_raw "<div>#{yield}</div>"

Is the same as this

output = yield
unsafe_raw "<div>#{output}</div>"

But if the block is doing Phlex HTML stuff, it’s not going to return anything it’s just going to push stuff to the buffer. Instead of yielding, you could capture the block to a string.

unsafe_raw "<div>#{capture(&)}</div>"

capture will temporarily change the internal buffer to a new string, yield, put the old buffer back and return the string.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by davidalejandroaguilar
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants