SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Confused on Chapter 6 Layouts

    I'm a bit confused on chapter 6 regarding the layout section, hopefully someone can point me in the right direction.

    I am trying to setup my rails application so that I can make a change to the main navigation layout in one spot. I am working on a .css file and a template on how I want the site to look. Without using frames, I want to have all pages call the 'top' and 'bottom' navigation (again no frames) and be able to have the main content in the 'main' page.

    From the book on page 159,
    <head><title>Shovell</title>
    <%=stylesheet_link_tag 'style' %>
    </head>
    <body><h1>Shovell</h1><%=yield %>

    Given my background description, can I point all of 'main' pages to the yield??

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Location
    Miami, FL
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's pretty much how it works, yes.

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A layout page basically defines the main HTML page into which your dynamic content will be inserted. It provides two basic services: stops you having to repeatedly enter standard HTML header and basic formatting on every page; and gives you a single framework to define your page styles so that they are consistent across multiple pages.

    The content of the layout page is wrapped around your standard view pages and this is done before the page is sent to the web server. So as far as your browser is concerned, it receives a single page - no frames.

    However, that doesn't mean you can't have dynamic content. For example look at this layout:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html
         PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
      <title>My Site : <&#37;= @page_title || controller.controller_name.capitalize + " (" + controller.action_name + ")" -%></title>
      <%= stylesheet_link_tag 'a_style_sheet' %>
      <%= javascript_include_tag :defaults %>
    </head>
    <body>
    <h1><%= @page_title -%></h1>
    <div id="flash_notice"><p><%= flash[:notice] %></p></div>
    
    <div id="main_content"><%= @content_for_layout %></div>
    
    <div id="footer"><%= render(:partial => "shared/footer") %></div>
    
    </body>
    </html>
    Standard HTML header information is defined in this one place. For example, the DOCTYPE declaration only has to be made once.

    However, Rails dynamic tools are still available - so that in this example, the page title has been constructed dynamically (either from @page_title that can be defined at the controller or view, or from the controller and action names)

    The layout can include locations for standard Rails output, like flash[:notice].

    By locating standard output such as @content_for_layout (does the same as yield in your example) within div tags in the layout, each section can be easily controlled and located via CSS. So you can get a frame type appearance and behaviour via CSS div blocks.

    For your specific problem notice how this example also includes a footer partial. The content displayed here will be defined within view file : shared/_footer.rhtml. This will give you your single location for footer information that will appear on every page that uses this layout. You can add as many of these as you like - so perhaps a navigation partial at the top of the page (between flash_notice and main_content for example).
    Last edited by ReggieB; Aug 6, 2007 at 04:51.

  4. #4
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply, as a new user to ruby I will have to read your response a couple of times to let it sink in.

    Right now my current site is basic html. I wanted to start converting it to ruby form so I can build on it. For the html layout having to only change the code once, should I not be using ruby? As a newbie to the group would there be to much time to invest vs. a different technology that I'm not aware of?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •