nesquena/rabl — pull request #422 by simsalabim (2013-03-15 06:42:46+00:00)
Title: Passing locals when rendering templates via partials or inheritance

### Passing locals when rendering templates via partials or inheritance ###

*Here's a copy-paste from README update below, hope this explains what I wanted to be implemented. And also I'm hoping you'll give this feature a try :)*

You may pass arbitrary set of locals when reusing your templates via partials or extending.
For example, we want to show on `posts/:id.json` the information regarding particular post with its comments.
But collection output of `posts.json` shouldn't contain any info about posts comments, and at the same time we want to
reuse a `app/views/posts/show.json.rabl` template here, as it seems to be logical.

Now we can use locals to do so as follows:

```ruby
# app/views/posts/index.json.rabl
collection @posts

extends('posts/show', :locals => {:hide_comments => true})
# or using partial instead of extend
# node(false) { |post| partial('posts/show', :object => :post, :locals => {:hide_comments => true})}
```

```ruby
# app/views/posts/show.json.rabl
object @post

attributes :id, :title, :body, :created_at
node(:comments) { |post| post.comments } unless locals[:hide_comments]
```