How to print something with erb?

D

Dominic Rose

Hello,
I'm having a problem to output things in the write order with erb1.9
and lighttpd . I don't know if it's the normal comportement of erb but
this is how it works for me:

Content of my ERB file: test{<%= 1 %>2<% puts 3 %>}

On my web browser I get this output:
3
test{12}

puts or print comes before any text.. Do you wich function instead of
puts would print test{123}?

Thanks wery much
 
D

Dominic Rose

Rein said:
Do not combine puts with <%= %> output in your erb templates. puts
prints to STDOUT, which may or may not be where your erb template is
rendered. Just use <%= %>.

If I want to print something on the middle of a script I should do
"%><%= thing_to_print %><%" and that's what I was trying to avoid. Do
you know if I can do somthing like that ?

def print string
$__erbout.write string
end

Except that I don't know what is the erbout real identifier.
 
P

Phrogz

If I want to print something on the middle of a script I should do
"%><%= thing_to_print %><%" and that's what I was trying to avoid. Do
you know if I can do somthing like that ?

def print string
    $__erbout.write string
end

Firstly:
As noted in the documentation, you can specify the erb out variable in
the call to ERB.new:
http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html#M000301
If you don't have control over that, you can look at the source and
see what (if any) name they are supplying and use that.


Secondly:
After I asked to have "puts" work almost 5 years ago, people on the
list
helped create a patch to ERB to allow print and puts to concatenate to
this string. See [1] below. This was followed by some discussion
(again prompted by me) for a RCR to allow this to work. See [2] below.
The discussion there is probably worth reading before we dive into
this again.

[1] http://blade.nagaokaut.ac.jp/cgi-bi...talk/152709?152641-153992+split-mode-vertical

[2] http://blade.nagaokaut.ac.jp/cgi-bi...talk/155537?155365-157410+split-mode-vertical
 
D

Dominic Rose

OK thank you that really helped. This is another piece to my puzzle.
Making work erb with lighttpd and without rails on both windows and
linux with a good error management and printing system is really hard,
not mentionning color syntaxing..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,888
Messages
2,569,964
Members
46,293
Latest member
BonnieHamb

Latest Threads

Top