# Passing Variables to a sub template

**URL:** <https://www.ruby-forum.com/t/passing-variables-to-a-sub-template/58468>\
**Category:** Rails\
**Created:** [April 21, 2006, 10:54pm UTC](https://www.ruby-forum.com/t/passing-variables-to-a-sub-template/58468 "2006-04-21T22:54:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [April 21, 2006, 10:54pm UTC](https://www.ruby-forum.com/t/passing-variables-to-a-sub-template/58468/1 "2006-04-21T22:54:35Z")

</div>

Hi,

I must be missing something very basic here.

I have a parent template and I am calling a sub template like…

\<%= render( :partial =\> “window\_title\_bar”, {“heading” =\> “Product  
Details”}) %\>

and in the sub template (\_window\_title\_bar.rhtml), i am doing

Heading: \<%= heading %\>

but I am getting syntax error in the master template at line

\<%= render( :partial =\> “window\_title\_bar”, {“heading” =\> “Requirement  
Details”}) %\>

Any help is appreciated. Thanks in Advance.

Pradeep

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [April 21, 2006, 11:23pm UTC](https://www.ruby-forum.com/t/passing-variables-to-a-sub-template/58468/2 "2006-04-21T23:23:54Z")

</div>

Pradeep

```
 > render( :partial => "window_title_bar", {"heading" =>

```

“Requirement Details”})

You forgot the ':locals =\> ’ part. It should read:  
\> render( :partial =\> “window\_title\_bar”, :locals =\> {“heading” =\>  
“Requirement Details”})

See  
[Peak Obsession](http://api.rubyonrails.com/classes/ActionController/Base.html#M000206)

Alain

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [April 21, 2006, 11:23pm UTC](https://www.ruby-forum.com/t/passing-variables-to-a-sub-template/58468/3 "2006-04-21T23:23:54Z")

</div>

On Apr 21, 2006, at 04:54 PM, Pradeep S. wrote:

> but I am getting syntax error in the master template at line
> 
> \<%= render( :partial =\> “window\_title\_bar”, {“heading” =\> “Requirement  
> Details”}) %\>

You need to specifically tell the render method that you are passing  
in local values for the partial template to use:

\<%= render( :partial =\> “window\_title\_bar”, :locals =\> {“heading” =\>  
“Requirement Details”}) %\>

I also recommend using symbols whenever you can, so I would actually  
use this version:

\<%= render( :partial =\> “window\_title\_bar”, :locals =\> {:heading =\>  
“Requirement Details”}) %\>

-Brian
