Module: Roda::RodaPlugins::ContentFor
- Defined in:
- lib/roda/plugins/content_for.rb
Overview
The content_for plugin is designed to be used with the render plugin, allowing you to store content inside one template, and retrieve that content inside a separate template. Most commonly, this is so view templates can set content for the layout template to display outside of the normal content pane.
In the template in which you want to store content, call content_for with a block:
<% content_for :foo do %>
Some content here.
<% end %>
You can also set the raw content as the second argument, instead of passing a block:
<% content_for :foo, "Some content" %>
In the template in which you want to retrieve content, call content_for without the block:
<%= content_for :foo %>
If content_for is used multiple times with the same key, by default, the last call will append previous calls. If you want to overwrite the previous content, pass the append: false
option when loading the plugin:
plugin :content_for, append: false
Defined Under Namespace
Modules: InstanceMethods
Class Method Summary collapse
-
.configure(app, opts = OPTS) ⇒ Object
Configure whether to append or overwrite if content_for is called multiple times to set data.
-
.load_dependencies(app, _opts = OPTS) ⇒ Object
Depend on the render plugin, since this plugin only makes sense when the render plugin is used.
Class Method Details
.configure(app, opts = OPTS) ⇒ Object
Configure whether to append or overwrite if content_for is called multiple times to set data. Overwrite is default, use the :append option to append.
46 47 48 |
# File 'lib/roda/plugins/content_for.rb', line 46 def self.configure(app, opts = OPTS) app.opts[:append_content_for] = opts.fetch(:append, true) end |
.load_dependencies(app, _opts = OPTS) ⇒ Object
Depend on the render plugin, since this plugin only makes sense when the render plugin is used.
39 40 41 |
# File 'lib/roda/plugins/content_for.rb', line 39 def self.load_dependencies(app, _opts = OPTS) app.plugin :render end |