#333 √ resolved
Matthew Windwer

Partial counter and yielding

Reported by Matthew Windwer | May 20th, 2008 @ 03:29 AM | in 0.9.4

This patch makes the following two local variables available inside of a partial when :with is specified:

1. partial_counter:: The current partial iteration (starting at 1).

2. partial_size:: The number of times the partial will be iterated.

I feel this is superior to the rails way, which 'magically' assigns a partial counter method to the template (my_partial_name_counter), since you can now write helper methods like this one to help with rendering views:

def last_item?
   partial_counter == partial_size
end

I also added support for yielding to each item in a collection, since I find that often I need this functionality, especially when I'm programatically generating partials, e.g.:

def user_partial_with_controls(controls_partial, opts={})
   partial(:user) do |with|
        @user_controls = partial(controls_partial, :with => with)
    end
end

Works nicely

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »