Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.


$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

2 Answers 2

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.