Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


$foo = 'bar'
$content = template('mymodule/maintemplate.erb')


<% bar = foo + "extra" %>

foobar = scope_function_template(['mymodule/subtemplate.erb'])


<%# here i want to access the variable bar %>
<%= bar %>

there is the function

<%= scope.lookupvar('::bar') %>

is there a kind of parent::bar in erb templateing, or can i pass some variables to the subtemplate, or can i only access the outer variable (of the .pp file) with ::foo

share|improve this question
check – andrekeller Nov 20 '12 at 22:21
@rbtux thank you very much. can you add it as answer so that i can accept it? – c33s Nov 21 '12 at 10:59
up vote 0 down vote accepted

As stated in this bugreport/feature request: there is a workaround using scope.setvar

<% bar = foo + "extra" %>

This is ugly but seems to work...

share|improve this answer
scope.unsetvar() was removed in… and is not available in puppet 3.x – jonhattan Apr 3 '13 at 12:45

So I read at that a TemplateWrapper could be used and I end up with this snippet:

newscope = scope.compiler.newscope(scope)
newscope.setvar(k, v)
wrapper =
wrapper.file = 'templatefile.erb'
<%= wrapper.result %>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.