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

Discussion in 'Ruby' started by Sfdesigner Sfdesigner, Aug 12, 2007.

  1. 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/.
     
    Sfdesigner Sfdesigner, Aug 12, 2007
    #1
    1. Advertising

  2. Sfdesigner Sfdesigner

    Jano Svitok Guest

    On 8/12/07, Sfdesigner Sfdesigner <> 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
     
    Jano Svitok, Aug 12, 2007
    #2
    1. Advertising

  3. 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/.
     
    Sfdesigner Sfdesigner, Aug 12, 2007
    #3
  4. Sfdesigner Sfdesigner, Aug 12, 2007
    #4
  5. Gregory Brown, Aug 13, 2007
    #5
  6. Sfdesigner Sfdesigner

    John Joyce Guest

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

    > On 8/12/07, 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") %>

    >
    > 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.
     
    John Joyce, Aug 13, 2007
    #6
  7. 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/.
     
    Stefan Rusterholz, Aug 14, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sameen
    Replies:
    2
    Views:
    451
    Victor Bazarov
    Aug 29, 2005
  2. Andreas Bogenberger
    Replies:
    3
    Views:
    947
    Andreas Bogenberger
    Feb 22, 2008
  3. srinivasan srinivas
    Replies:
    5
    Views:
    345
  4. Jochen Brenzlinger
    Replies:
    7
    Views:
    5,610
    Roedy Green
    Sep 15, 2011
  5. Martin Nemzow
    Replies:
    0
    Views:
    108
    Martin Nemzow
    Jun 8, 2006
Loading...

Share This Page