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

  • Thread starter Sfdesigner Sfdesigner
  • Start date
S

Sfdesigner Sfdesigner

Hi,

I have a header.html file that contains <h1>client name</h1>.

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

<html>
<body>
<% include 'header.html' %>
</body>
</html>
 
J

Jano Svitok

Hi,

I have a header.html file that contains <h1>client name</h1>.

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

<html>
<body>
<% include 'header.html' %>
</body>
</html>

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
 
S

Sfdesigner Sfdesigner

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?
 
J

John Joyce

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.
 
S

Stefan Rusterholz

Sfdesigner said:
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
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top