[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Sfdesigner Sfdesigner

8/12/2007 7:25:00 PM

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>
--
Posted via http://www.ruby-....

6 Answers

Jano Svitok

8/12/2007 8:00:00 PM

0

On 8/12/07, Sfdesigner Sfdesigner <daniel@seniorartdirector.com> wrote:
> 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

Sfdesigner Sfdesigner

8/12/2007 10:06:00 PM

0

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?
--
Posted via http://www.ruby-....

Sfdesigner Sfdesigner

8/12/2007 10:50:00 PM

0

> Then http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
> may
> hopefully be helpful.
>
> Felix

Thanks! I got this to work

<% print IO.read("header.html") %>

DAN
--
Posted via http://www.ruby-....

Gregory Brown

8/13/2007 1:37:00 AM

0

On 8/12/07, Sfdesigner Sfdesigner <daniel@seniorartdirector.com> wrote:
> > Then http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
> > 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.

John Joyce

8/13/2007 8:26:00 AM

0


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

> On 8/12/07, Sfdesigner Sfdesigner <daniel@seniorartdirector.com>
> wrote:
>>> Then http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/...
>>> 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.
>

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.


Stefan Rusterholz

8/14/2007 12:47:00 AM

0

Sfdesigner Sfdesigner wrote:
>> Then http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
>> 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
--
Posted via http://www.ruby-....