Sha256: a52016e4061dd891859c6d268f8f944257911cf772a3fab79cd904253b56e5ff

Contents?: true

Size: 886 Bytes

Versions: 14

Compression:

Stored size: 886 Bytes

Contents

require 'tilt/erb'
template = Tilt::ERBTemplate.new('templates/foo.erb')
joe = Person.find('joe')
output = template.render(joe, :x => 35, :y => 42)
# If no scope is provided, the template is evaluated within the context of an object created with Object.new.

# A single Template instance's render method may be called multiple times with different scope and locals arguments. Continuing the previous example, we render the same compiled template but this time in jane's scope:

jane = Person.find('jane')
output = template.render(jane, :x => 22, :y => nil)
# Blocks can be passed to render for templates that support running arbitrary ruby code (usually with some form of yield). For instance, assuming the following in foo.erb:

# Hey <%= yield %>!
# The block passed to render is called on yield:

template = Tilt::ERBTemplate.new('foo.erb')
template.render { 'Joe' }
# => "Hey Joe!"

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
render_me_pretty-0.9.0 tilt_examples.rb
render_me_pretty-0.8.4 tilt_examples.rb
render_me_pretty-0.8.3 tilt_examples.rb
render_me_pretty-0.8.2 tilt_examples.rb
render_me_pretty-0.8.1 tilt_examples.rb
render_me_pretty-0.8.0 tilt_examples.rb
render_me_pretty-0.7.1 tilt_examples.rb
render_me_pretty-0.7.0 tilt_examples.rb
ufo-3.0.1 vendor/render_me_pretty/tilt_examples.rb
render_me_pretty-0.6.0 tilt_examples.rb
render_me_pretty-0.5.0 tilt_examples.rb
render_me_pretty-0.4.0 tilt_examples.rb
render_me_pretty-0.2.0 tilt_examples.rb
render_me_pretty-0.1.0 tilt_examples.rb