# File lib/merb-core/controller/mixins/render.rb, line 414
  def _template_for(context, content_type, controller=nil, template=nil, locals=[])
    tmp = self.class._templates_for[[context, content_type, controller, template, locals]]
    return tmp if tmp

    template_method, template_location = nil, nil

    # absolute path to a template (:template => "/foo/bar")
    if template.is_a?(String) && template =~ %r{^/}
      template_location = self._absolute_template_location(template, content_type)
      return [_template_method_for(template_location, locals), template_location]
    end

    self.class._template_roots.reverse_each do |root, template_meth|
      # :template => "foo/bar.html" where root / "foo/bar.html.*" exists
      if template
        template_location = root / self.send(template_meth, template, content_type, nil)
      # :layout => "foo" where root / "layouts" / "#{controller}.html.*" exists        
      else
        template_location = root / self.send(template_meth, context, content_type, controller)
      end
    
      break if template_method = _template_method_for(template_location.to_s, locals)
    end

    # template_location is a Pathname
    ret = [template_method, template_location.to_s]
    unless Merb::Config[:reload_templates]
      self.class._templates_for[[context, content_type, controller, template, locals]] = ret
    end
    ret
  end