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

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-forum.com/.

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

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

···

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>

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

···

-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Sfdesigner Sfdesigner
Sent: Sunday, August 12, 2007 12:25 PM
To: ruby-talk ML
Subject: Can .rhtml files include text from .txt or .html file?

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-forum.com/\.

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

Felix

···

-----Original Message-----
From: Felix Windt [mailto:fwmailinglists@gmail.com]
Sent: Sunday, August 12, 2007 1:10 PM
To: ruby-talk ML
Subject: Re: Can .rhtml files include text from .txt or .html file?

> -----Original Message-----
> From: list-bounce@example.com
> [mailto:list-bounce@example.com] On Behalf Of Sfdesigner Sfdesigner
> Sent: Sunday, August 12, 2007 12:25 PM
> To: ruby-talk ML
> Subject: Can .rhtml files include text from .txt or .html file?
>
> 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-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?

···

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

···

-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Sfdesigner Sfdesigner
Sent: Sunday, August 12, 2007 3:06 PM
To: ruby-talk ML
Subject: Re: Can .rhtml files include text from .txt or .html file?

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-forum.com/\.

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

···

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

You can also do

<%= IO.read 'header.html' %>

no need for the print.

···

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

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

···

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

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.

···

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