SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Los Angeles CA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Automating partials?

    Hello, sorry for Ruby-newb question but I'm working on a project using RoR and it's my first time ever using it. I should probably also mention that I'm not a programmer but an interface designer.

    The site I'm developing has about 40 or so page templates. The majority of the templates are laid out in a two column style, one for the content and the other for a sidebar. The sidebars carry what I call contextual "information modules" of images and text; some might appear only on one template whereas others will appears on multiple templates.

    What I'd like to do is drop each module into a partial and then write a control or method that will appear on all templates that pulls in the partial based on the template CSS body class.

    Is this the most efficient way for handling something like this? Thanks.

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand exactly what you want, but you can use capture:

    Code:
    // in the page-specific template:
    
    <!-- put content of content column here -->
    
    <% @sidebar = capture do %>
    <!-- put content of sidebar column here -->
    <% end %>
    And then in the layout:

    Code:
    <div class="content">
    <%= yield %>
    </div>
    
    <div class="sidebar">
    <%= @sidebar %>
    </div>

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Los Angeles CA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Is there a way of randomizing a group or collection of partials?

    Quote Originally Posted by Fenrir2
    I don't understand exactly what you want, but you can use capture:

    Code:
    // in the page-specific template:
    
    <!-- put content of content column here -->
    
    <% @sidebar = capture do %>
    <!-- put content of sidebar column here -->
    <% end %>
    And then in the layout:

    Code:
    <div class="content">
    <%= yield %>
    </div>
    
    <div class="sidebar">
    <%= @sidebar %>
    </div>

  4. #4
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know what you mean exactly, but you can randomize the collection you'll use this way:

    collection.sort_by{rand}


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
  •