# Help with Custom ERB Templates

**URL:** <https://www.ruby-forum.com/t/help-with-custom-erb-templates/147063>\
**Category:** Ruby\
**Created:** [August 28, 2008, 6:39am UTC](https://www.ruby-forum.com/t/help-with-custom-erb-templates/147063 "2008-08-28T06:39:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [August 28, 2008, 6:39am UTC](https://www.ruby-forum.com/t/help-with-custom-erb-templates/147063/1 "2008-08-28T06:39:46Z")

</div>

I’m trying to create a custom erb template that allows me to mix MXML  
and Ruby. I’m having problems coming from the way I wish to implement  
it.

In MXML you need tags which I would like to use Ruby to create.

Take note of the following MXML snippet:

\<mx:Application “xmlns:mx”=“[http://www.adobe.com/2006/mxml](http://www.adobe.com/2006/mxml)” \>  
blah blah blah  
\</mx:Application\>

I would like to have an mxml/erb file create that in Ruby by doing  
something like the following:

\<% MX::Application.new{|app|  
app[“xmlns:mx”]=“[http://www.adobe.com/2006/mxml](http://www.adobe.com/2006/mxml)” %\>  
blah blah blah  
\<% } %\>

In my current solution, ERB runs the Ruby code and generates the tag  
with the proper options but displays the non-ruby part afterwards such  
as this:

\<mx:Application “xmlns:mx”=“[http://www.adobe.com/2006/mxml](http://www.adobe.com/2006/mxml)” \>  
\</mx:Application\>

blah blah blah

Would there be any way to capture the “blah blah blah” as a string and  
somehow pass that to the underlying Ruby so it can be told when to  
print?

I would really like for the curly-braces to signify the start and end of  
a tag.

I suppose the functionality I’m trying to mimic is similar to form\_tag  
in Rails

\<% form\_tag ‘/posts’ do -%\>

\<%= submit\_tag ‘Save’ %\>
  
\<% end -%\>

Thanks

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [August 28, 2008, 7:28am UTC](https://www.ruby-forum.com/t/help-with-custom-erb-templates/147063/2 "2008-08-28T07:28:38Z")

</div>

Nevermind! [http://builder.rubyforge.org/](http://builder.rubyforge.org/) seems to be a good base for  
combining this and ERB.
