Can .rhtml files include text from .txt or .html file?

Hi,

I have a header.html file that contains

client name

.

Is there some way to get the header.html file content into a index.rhtml
that looks something like this?

<% include 'header.html' %>

how about

<% File.open(“header.html”) do |line| %>
<%= line %>
<% end %>

since you can run arbitrary ruby code in .rhtml files.

On 8/12/07, Sfdesigner S. [email protected] wrote:

I’m not too much at home with rails, but try

<%= File.read ‘header.html’ %>

There might be a more clever way to do this, especially regarding to
paths…
Then there is a command to include a sub-template, and I guess you can
use that too.

Jano

Is there some way to get the header.html file content into a
index.rhtml that looks something like this?

<% include 'header.html' %> -- Posted via http://www.ruby-forum.com/.

Look at http://api.rubyonrails.org/classes/ActionView/Partials.html, you
could implement this as a template, an action or simply render the file
directly.

HTH,

Felix

I’m actually not using Rails myself. Just using eruby interpreter on
.rhtml files.

I was thinking Ruby might have an easy method similar to Rials, shtml,
or php includes.

Any other ideas?

I was thinking Ruby might have an easy method similar to
Rials, shtml, or php includes.

Any other ideas?

Posted via http://www.ruby-forum.com/.

Then http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/245920
may
hopefully be helpful.

Felix

Then http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/245920
may
hopefully be helpful.

Felix

Thanks! I got this to work

<% print IO.read(“header.html”) %>

DAN

To: ruby-talk ML

HTH,

Felix

Bad link in the clipboard, I apologize -
ActionController::Base is
the
correct documentation.

Felix

On 8/12/07, Sfdesigner S. [email protected] wrote:

Then http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/245920
may
hopefully be helpful.

Felix

Thanks! I got this to work

<% print IO.read(“header.html”) %>

You can also do

<%= IO.read ‘header.html’ %>

no need for the print.

On Aug 12, 2007, at 8:36 PM, Gregory B. wrote:

<% print IO.read(“header.html”) %>

You can also do

<%= IO.read ‘header.html’ %>

no need for the print.

One tip though, you don’t have to use rhtml as the file extension to
use ERb.
It’s really a Rails thing to require that extension.
eruby itself can process text from just about whatever you use it for.
Truth is, file extensions don’t really mean much at all in many cases.
Apache does care about them though, and you would need to edit
httpd.conf (or one of the other conf files) or htaccess to tell it
what file extensions are files that should be sent to Eruby for
processing first.

Sfdesigner S. wrote:

Then http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/245920
may
hopefully be helpful.

Felix

Thanks! I got this to work

<% print IO.read(“header.html”) %>

DAN

That print is most likely introducing buggy behaviour into your thingy.
a) print prints to $stdout, whatever renders your template doesn’t
necessarily print to $stdout, so header.html might be printed somewhere
else than the rest of the template
b) even if that’s not the case, it will screw up timing, the print
happens immediatly when the template is rendered, which is before it
is printed, try to do that with a “footer.html” on the very end of your
template and you’ll see what I mean - your footer.html will be printed
on top

Use what the others more than once suggested you: <%= File.read(path) %>

Regards
Stefan