Application Helpers

Render Helpers

This component provides a number of rendering helpers making the process of displaying templates a bit easier. This plugin also has support for useful additions such as partials (with support for :collection) for the templating system.

Using render plugin helpers is extremely simple. If you want to render an erb template in your view path:

render :erb, 'path/to/erb/template'

or using haml templates works just as well:

render :haml, 'path/to/haml/template'

There is also a method which renders the first view matching the path and removes the need to define an engine:

render 'path/to/any/template'

It is worth noting these are mostly for convenience. With nested view file paths in Sinatra, this becomes tiresome:

haml :"the/path/to/file"
erb "/path/to/file".to_sym

Finally, we have the all-important partials support for rendering mini-templates onto a page:

partial 'photo/item', :object => @photo, :locals => { :foo => 'bar' }
partial 'photo/item', :collection => @photos

List of Render Helpers

  • render(engine, data, options, locals)
    • Renders the specified template with the given options
    • render 'user/new'
    • render :erb, 'users/new', :layout => false
  • partial(template, *args)
    • Renders the html related to the partial template for object or collection
    • partial 'photo/item', :object => @photo, :locals => { :foo => 'bar' }
    • partial 'photo/item', :collection => @photos

last updated: 2016-10-23

comments powered by Disqus