Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Question About Capturing Content #6

Open
evanleck opened this issue Jun 8, 2016 · 0 comments
Open

A Question About Capturing Content #6

evanleck opened this issue Jun 8, 2016 · 0 comments

Comments

@evanleck
Copy link

evanleck commented Jun 8, 2016

Hello!

I'm trying to create a helper similar to sinatra-contrib's content_for method and have a quick question: how would you stash the content from a block evaluating inside of a mote template into another buffer? In other words, capture the content in the block and display it somewhere else but not where the block resides.

I have the following so far:

def content_for(key, &content)
  @_content_for ||= {}

  if content
    @_content_for[key] ||= []
    @_content_for[key].push Mote.parse(yield(content)).call
  elsif @_content_for[key]
    @_content_for[key].join
  end
end

Which gets called like this:

% content_for(:jumbotron) do
  <h1>Home</h1>
% end

And output like this:

% if content_for(:jumbotron)
  <div class='jumbotron'>
    <div class='container'>
      {{ content_for(:jumbotron) }}
    </div>
  </div>
% end

I'd like to capture that <h1> block and display it elsewhere, removing it from that location. Currently, it shows in both places.

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant