# Erubis subtemplates

**URL:** <https://www.ruby-forum.com/t/erubis-subtemplates/132245>\
**Category:** Ruby\
**Created:** [March 18, 2008, 9:30am UTC](https://www.ruby-forum.com/t/erubis-subtemplates/132245 "2008-03-18T09:30:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [March 18, 2008, 9:30am UTC](https://www.ruby-forum.com/t/erubis-subtemplates/132245/1 "2008-03-18T09:30:53Z")

</div>

Is it possible to do subtemplating with erubis?

I achieved similar behaviour with ERB the following way:

template = ERB.new(File.read(‘template.rhtml’))

— in the template i put the following code

 \<%= ERB.new(IO.read('subtemplate1'), nil, nil, '\_sub1').result(binding()) %\> \<%= ERB.new(IO.read('subtemplate2'), nil, nil, '\_sub2').result(binding()) %\>
* * *

page = template.result(binding())

As a result i get all templates mixed together.

How do i do that with erubis?

---

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [March 18, 2008, 4:52pm UTC](https://www.ruby-forum.com/t/erubis-subtemplates/132245/2 "2008-03-18T16:52:06Z")

</div>

Christian K. wrote:

> Is it possible to do subtemplating with erubis?
> 
> I achieved similar behaviour with ERB the following way:
> 
> template = ERB.new(File.read(‘template.rhtml’))
> 
> — in the template i put the following code
> 
> \<%= ERB.new(IO.read('subtemplate1'), nil, nil, '\_sub1').result(binding()) %\> \<%= ERB.new(IO.read('subtemplate2'), nil, nil, '\_sub2').result(binding()) %\>
> * * *
> 
> page = template.result(binding())
> 
> As a result i get all templates mixed together.
> 
> How do i do that with erubis?

I’m using tenjin now. It has subtemplating built in.

[http://www.kuwata-lab.com/tenjin/](http://www.kuwata-lab.com/tenjin/)
