-
Notifications
You must be signed in to change notification settings - Fork 335
Reusing templates
nesquena edited this page Sep 23, 2012
·
9 revisions
There are a few ways to re-use templates:
Partial is used to access the representation of another object for use in node
:
object @post
node :categories do |post|
post.categories.map do |category|
partial("categories/show", :object => category)
end
end
Extends is used to inherit from another template:
object @post
child :categories do
extends "categories/show"
end
Partials allow you to reuse templates for multiple objects and extends allow you to reuse templates from multiple templates.
# users/show.rabl
object @presentation
node :blogger do
partial "writers/info", object: presentation.blogger
end
node :author do
partial "writers/info", object: presentation.author
end
# writers/_info.rabl
object @writer # ignored when used as a partial so I usually don't specify it
attributes :name, :first_published_date, :birth_date, :death_date
child :publications do
extends "publications/public"
end
# publications/public.rabl
attributes :title, :publication_date, :publisher
# publications/show.rabl
object @publication
extends "publications/public"