# How to print stuff in RTHML embedded code (equiv to php "ech

**URL:** <https://www.ruby-forum.com/t/how-to-print-stuff-in-rthml-embedded-code-equiv-to-php-ech/77619>\
**Category:** Ruby\
**Created:** [March 7, 2006, 4:51am UTC](https://www.ruby-forum.com/t/how-to-print-stuff-in-rthml-embedded-code-equiv-to-php-ech/77619 "2006-03-07T04:51:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Namor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@Namor](https://www.ruby-forum.com/u/Namor)\
**Post date:** [March 7, 2006, 4:51am UTC](https://www.ruby-forum.com/t/how-to-print-stuff-in-rthml-embedded-code-equiv-to-php-ech/77619/1 "2006-03-07T04:51:16Z")

</div>

Hi I got a very noob question which i cant understand why i cant do  
things like this…

eg… inside.  
helloworld.rhtml

\<% puts "hello" puts "world" puts "something something" %\>

I know i can do this easily in php

\<?php echo "yes this works" echo "testing 123" echo "yes this works" ?\>

Can someone help me?

---

<div class="post-metadata">

**Author:** ![Namor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@Namor](https://www.ruby-forum.com/u/Namor)\
**Post date:** [March 7, 2006, 6:49am UTC](https://www.ruby-forum.com/t/how-to-print-stuff-in-rthml-embedded-code-equiv-to-php-ech/77619/2 "2006-03-07T06:49:15Z")

</div>

It’s a simple as:  
\<%= “hello world!” %\>

See also:  
[http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html](http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html)

Hope this helps,  
Jonathan

---

<div class="post-metadata">

**Author:** ![Namor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@Namor](https://www.ruby-forum.com/u/Namor)\
**Post date:** [March 7, 2006, 7:31am UTC](https://www.ruby-forum.com/t/how-to-print-stuff-in-rthml-embedded-code-equiv-to-php-ech/77619/3 "2006-03-07T07:31:29Z")

</div>

hmmm  
so means that for my program

helloworld.rhtml

\<%= puts "hello" %\> \<%= puts "world" %\> \<%= puts "something something" %\>

i have to do that? that is obviously way harder to code…  
and if it was in between a loop or something just say for debugging…  
i got to close the loop and then bracket it… then come back again?  
man  
there must be an easier way???

---

<div class="post-metadata">

**Author:** ![Namor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@Namor](https://www.ruby-forum.com/u/Namor)\
**Post date:** [March 7, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/how-to-print-stuff-in-rthml-embedded-code-equiv-to-php-ech/77619/4 "2006-03-07T18:41:18Z")

</div>

Namor wrote:

> ```
> puts "world"
> 
> ```
> 
> ?\>
> 
> Can someone help me?

I’m not sure if this helps or even if it’s good  
I don’t like to open and close with \<%…%\> repeatedly.  
So I use the following.

\<%  
\_erbout \<\< “hello”  
\_erbout \<\< “world”  
\_erbout \<\< “something something”  
%\>

Sam

---

<div class="post-metadata">

**Author:** ![Namor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@Namor](https://www.ruby-forum.com/u/Namor)\
**Post date:** [March 7, 2006, 7:18pm UTC](https://www.ruby-forum.com/t/how-to-print-stuff-in-rthml-embedded-code-equiv-to-php-ech/77619/5 "2006-03-07T19:18:01Z")

</div>

On Mar 7, 2006, at 1:28 AM, Namor wrote:

> i have to do that? that is obviously way harder to code…  
> and if it was in between a loop or something just say for debugging…  
> i got to close the loop and then bracket it… then come back again?  
> man  
> there must be an easier way???

Not exactly, you do this:

\<%= "hello" %\> etc...

\<%= is roughly analogous to “puts” or “print”

---

<div class="post-metadata">

**Author:** ![Namor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@Namor](https://www.ruby-forum.com/u/Namor)\
**Post date:** [March 7, 2006, 10:55pm UTC](https://www.ruby-forum.com/t/how-to-print-stuff-in-rthml-embedded-code-equiv-to-php-ech/77619/6 "2006-03-07T22:55:18Z")

</div>

ERB doesn’t allow you to use ‘print’ or ‘puts’ in eRuby script.  
You can use print statement if you use Erubis instead of ERB.  
Erubis is an implementation of eRuby which has some advantages over  
ERB.  
[http://rubyforge.org/projects/erubis/](http://rubyforge.org/projects/erubis/)

For example, the following code is available with Eruby::PrintEruby  
or Eruby::StdoutEruby class.

\<% print "hello\n" print "world\n" print "something something\n" %\>

See doc/users-guide.html in the archive.

---

<div class="post-metadata">

**Author:** ![Namor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@Namor](https://www.ruby-forum.com/u/Namor)\
**Post date:** [August 3, 2006, 2:22pm UTC](https://www.ruby-forum.com/t/how-to-print-stuff-in-rthml-embedded-code-equiv-to-php-ech/77619/7 "2006-08-03T14:22:23Z")

</div>

\<%= @articles.join("\<br/\>") %\>

---

<div class="post-metadata">

**Author:** ![Namor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@Namor](https://www.ruby-forum.com/u/Namor)\
**Post date:** [August 3, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/how-to-print-stuff-in-rthml-embedded-code-equiv-to-php-ech/77619/8 "2006-08-03T14:21:54Z")

</div>

A better example would be

if i was to do some debugging  
it would have to be

\<% @articles.map { |x| %\>  
\<%= x.name %\>  
\<% } %\>

instead of  
\<%= @articles.map { |x| echo x.name } %\> ???

wouldnt that be so difficult to type out and to read as well?
