Skip to content

Commit a5c8855

Browse files
dylhackp8
andcommitted
Add :variant option to Partial Rendering
Co-authored-by: Petrik de Heus <[email protected]>
1 parent 76efa0f commit a5c8855

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

actionview/lib/action_view/renderer/partial_renderer.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ module ActionView
4848
#
4949
# <%= render partial: "account", locals: { user: @buyer } %>
5050
#
51+
# == \Rendering variants of a partial
52+
#
53+
# The <tt>:variants</tt> option can be used to render a different template variant of a partial. For instance:
54+
#
55+
# <%= render partial: "account", variants: :mobile %>
56+
#
57+
# This will render <tt>_account.html+mobile.erb</tt>. This option also accepts multiple variants
58+
# like so:
59+
#
60+
# <%= render partial: "account", variants: [:desktop, :mobile] %>
61+
#
62+
# This will look for the following templates and render the first one that exists:
63+
# * <tt>_account.html+desktop.erb</tt>
64+
# * <tt>_account.html+mobile.erb</tt>
65+
# * <tt>_account.html.erb</tt>
66+
#
5167
# == \Rendering a collection of partials
5268
#
5369
# The example of partial use describes a familiar pattern where a template needs to iterate over an array and

0 commit comments

Comments
 (0)