Questions tagged [partials]

Partials are often synonym for templates, which can even also be called partial templates.

Partials are often synonym for templates, which can even also be called partial templates.

763 questions
249
votes
12 answers

optional local variables in rails partial templates: how do I get out of the (defined? foo) mess?

I've been a bad kid and used the following syntax in my partial templates to set default values for local variables if a value wasn't explicitly defined in the :locals hash when rendering the partial -- <% foo = default_value unless (defined? foo)…
brahn
  • 12,096
  • 11
  • 39
  • 49
246
votes
13 answers

Is it possible to import a whole directory in sass using @import?

I'm modularizing my stylesheets with SASS partials like so: @import partials/header @import partials/viewport @import partials/footer @import partials/forms @import partials/list_container @import partials/info_container @import…
corroded
  • 21,406
  • 19
  • 83
  • 132
56
votes
7 answers

Where to put partials shared by the whole application in Rails?

Where would I go about placing partial files shared by more than one model? I have a page called crop.html.erb that is used for one model - Photo. Now I would like to use it for another model called User as well. I could copy and paste the code but…
Yuval Karmi
  • 26,277
  • 39
  • 124
  • 175
45
votes
6 answers

When to use Helpers instead of Partials

In a rails application, in which situation would you use a partial and when would you use a helper? I find both very similar, since they represent markup fragments. Is there a convention around this? which is the 'rails way' of using them? Thanks!
Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232
44
votes
6 answers

Devise Custom Routes and Login Pages

I'm trying to get Custom Routes working in my Rails application (Ruby 1.9.2 with Rails 3). This is my config/routes.rb file match '/dashboard' => 'home#dashboard', :as => 'user_root' devise_for :user do get "/login", :to => "devise/sessions#new"…
Karthik Kastury
  • 587
  • 1
  • 5
  • 11
42
votes
3 answers

Sass @import using leading underscore

I understand that it is best practise to import SASS/SCSS partials without using the leading underscore; e.g. @import 'normalize-scss/normalize'; // this imports ./normalize-scss/_normalize.scss My question for nerdy completeness is, are there any…
Timidfriendly
  • 3,224
  • 4
  • 27
  • 36
40
votes
8 answers

How can I automatically render partials using markdown in Rails 3?

I want to have some of my partials as markdown snippets. What is the easiest way to render them using the standard rails erb templating? Ideally, I'd like to do something like this: If I have a partial in app/views/_my_partial.md.erb: My awesome…
Jacob
  • 22,785
  • 8
  • 39
  • 55
38
votes
3 answers

Rails passing form_for object to partial

I would like to pass the form_for object to a partial: <%= form_for @price do |f| %> ... <%= render :partial => "price_page", :object => @price, :as => :f %> ... <% end %> When I call: f.radio_button Brings the error: undefined method…
Harry
  • 1,659
  • 5
  • 19
  • 34
32
votes
3 answers

Angular JS and partials

Is it possible to embed html page in another one in angular js? If so, how to do it? Here in their tutorial, the partial is not embedded in the page but it's like different page where you go when you click on one of the items. (see demo)
ParPar
  • 7,355
  • 7
  • 43
  • 56
31
votes
2 answers

Angularjs: Multiples partials in single html?

Is possible retrieve multiples html partials in one single html? I've the next situation: Template: {header} {main} {footer} /index: header:"Welcome" main:"welcome text" footer:"" /help: header:"Help title" main:"faq tips" footer"Back to…
Jose Ignacio Larghi
  • 488
  • 1
  • 7
  • 11
28
votes
2 answers

Inside Express/EJS templates, what is cleanest way to loop through an array?

I have an Express.js app set up using EJS templates. I successfully looped through an array with classic JS syntax: <% for (var i = 0; i < myArray.length; i++) { this = myArray[i]; // display properties of this } %> But I'm wondering, is…
dylanized
  • 3,765
  • 6
  • 32
  • 44
26
votes
1 answer

How to use HTML in Express framework with nunjucks- no jade

I have been using sendFile method to render Html in Express project. I would like to use partials with my project. And, not switch to jade. Is there a way to use traditional HTML with partials in Express 3.x. I have tried ejs, but dont understand…
Merlin
  • 24,552
  • 41
  • 131
  • 206
25
votes
3 answers

Rails 4 rendering a partial with ajax, jquery, :remote => true, and respond_to

It seems like rendering a page dynamically with AJAX in response to a submitted form is common. None of the other similar questions are focused around how to do this in a general way. The best blog post I could find on the subject was here:…
emery
  • 8,603
  • 10
  • 44
  • 51
17
votes
2 answers

Using variables for a partial template

I'm definitely missing something about the way Handlebars works. I need to call different partials depending on the value of a variable. Currently the only way I've found to do it is this: