Turns out the below is not a good description of what I needed. Through all this research I've figured out how to ask the question I should have been asking. New post: here. Leaving this question in case it benefits someone else.
I am building a site with multiple "blogs" activated and there are instances where it would be useful to be able to get things like the blog.prefix
from config.rb
. I know you can set
variables and use instance variables via config.rb
but that means in templates I have to know which blog I'm in which doesn't solve my problem. (I want one layout for all the blogs, not a duplicate one for each.)
Is there a way I can get the blog.prefix
and other activation variables from config.rb
and use it in a layout like:
<p>The blog prefix is: <%= blog.prefix %></p>
UPDATE
I've tried passing instance variables in the page do
block, as well as using locals => { :variable = value }
and both result in an Error: cannot find _auto_layout
when rendering the page.
I original posted this on the middleman forums but Stackoverflow tends to have more eyes on it. :-D
UPDATE 2
If I have to have a separate variable (say blog1_prefix
, blog2_prefix
, and blog3_prefix
) for each then I have to know which variable I'm calling from the template. I need the template to know which blog it's getting the prefix (or whatever) for.
In my config.rb
I have a block that looks something like this:
my_blogs = ["blog1", "blog2", "blog3"]
my_blogs.each do |my_blog|
activate :blog do |blog|
blog.prefix = my_blog
end
end
Is there a way I can set one variable that will allow the layout to know which blog it is being called on so I can do something like in my example above:
<p>The blog prefix is: <%= blog.prefix %></p>
That would render on each of the three blogs from a single layout:
<p>The blog prefix is: blog1</p>
<p>The blog prefix is: blog2</p>
<p>The blog prefix is: blog3</p>