Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use a partial in a layout template?

I have a partial that I'd like to use in a layout but when I load up a page it'll look in a different folder for the partial.

So for my layout I've got.

%html
  %head
%body
  .content
    = yield
  .footer
  = render :partial => 'tracking'

And in my layouts folder I have the partial file "app/views/layouts/_tracking.html.haml" that I'd like to use in the layout for all pages. But when I load up a page It'll give me an error saying it can't find the template "products/_tracking.erb"

like image 778
Vizjerai Avatar asked Sep 23 '09 19:09

Vizjerai


People also ask

What are template partials?

Template partials are small bits of reusable template or tag parts. You could create a Template partial for any number of purposes, anywhere that you need to reuse a small portion of a template, including partial or complete tags, other variables, etc.

How do you create a partial in HTML?

The tag {% include %} is how a partial is added to a page. By default, Eleventy looks for partials in the _includes folder. For example, to include header HTML that is in the file _includes/_head. html, the tag would be {% include _head.

What are partials used?

A partial is a denture that replaces the missing teeth when someone still has multiple natural teeth remaining. It is removable, not attached permanently to the teeth or jawbones. A removable partial denture.

What are partials in development?

Partials are Mustache template files that are included in a page, similar to an include, import, or a nested template. You don't determine where partials display in your templates. Your templates only determine the layout of the large blocks of content, like headers, banners, footer, and sections.


2 Answers

just use

= render :partial => '/layouts/tracking'
like image 102
tal Avatar answered Oct 03 '22 19:10

tal


I think you just pass it a full path to it, like

<%= render "shared/menu" %>

ref: 3.4.1 second example here: http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials

like image 37
rogerdpack Avatar answered Oct 03 '22 18:10

rogerdpack