# File lib/merb-core/controller/mixins/render.rb, line 291
  def partial(template, opts={})

    # partial :foo becomes "#{controller_name}/_foo"
    # partial "foo/bar" becomes "foo/_bar"
    template = template.to_s
    if template =~ %r{^/}
      template_path = File.dirname(template) / "_#{File.basename(template)}"
    else
      kontroller = (m = template.match(/.*(?=\/)/)) ? m[0] : controller_name
    end
    template = "_#{File.basename(template)}"

    # This handles no :with as well
    with = [opts.delete(:with)].flatten
    as = (opts.delete(:as) || template.match(%r[(?:.*/)?_([^\./]*)])[1]).to_sym

    # Ensure that as is in the locals hash even if it isn't passed in here
    # so that it's included in the preamble. 
    locals = opts.merge(:collection_index => -1, :collection_size => with.size, as => opts[as])
    template_method, template_location = _template_for(
      template, 
      opts.delete(:format) || content_type, 
      kontroller, 
      template_path, 
      locals.keys)
    
    # this handles an edge-case where the name of the partial is _foo.* and your opts
    # have :foo as a key.
    named_local = opts.key?(as)
    
    sent_template = with.map do |temp|
      locals[as] = temp unless named_local

      if template_method && self.respond_to?(template_method)
        locals[:collection_index] += 1
        send(template_method, locals)
      else
        raise TemplateNotFound, "Could not find template at #{template_location}.*"
      end
    end.join
    
    sent_template
  end