cloudhead / toto

the 10 second blog-engine for hackers
MIT License
1.49k stars 244 forks source link

Call YAML-derived data from layout.rhtml #37

Closed davejacobs closed 14 years ago

davejacobs commented 14 years ago

I've browsed through the source code and can't figure out how to call YAML-derived values from my layout page.

I want to optimize my blog's SEO and dynamically generate the description and keywords for every page. (I know, I know... keywords don't affect page rank. Still, I like being semi-semantic.)

I've tried calling <%= description %> from the template and nothing shows up! Right now, it falls back to a default description I define in config.ru (and call via @config[:description]), but I want individual descriptions for each page.

It looks like the standard tags (title, date, author) have explicit methods defining them in the source, methods that can be called from a template. But method_missing doesn't work from inside that template file.

(I realize there is a method_missing definition elsewhere in the source, but I think that's scoped so that it doesn't work within my layout.rhtml.)

Do I really need to patch in a new method for every YAML tag I'm going to call from the template?

davejacobs commented 14 years ago

Sorry, I missed the part in the Wiki explaining this feature. For anyone who's reading and still has this question, you access non-standard YAML variables from the @context hash.

cloudhead commented 14 years ago

Yea, this is sort of a non-documented hack. The wiki isn't entirely correct actually, because you don't need to use @context when you have access to the article object. It's just in the case where you need to access the data from the layout, which is what you're trying to do.

davejacobs commented 14 years ago

Excellent.