Issue #6492 has been updated by Markus Roberts.

Affected Puppet version deleted (2.6.5rc5)

I would call this not-a-bug.  Neither puppet, erb, nor ruby have semantics that 
allow a called entity access to the local variables of the caller, and for good 
reason.

If this were still unassigned I would have rejected it (sorry Peter) but as 
it's been claimed by Nigel I'll just lodge a strong objection.

P.S. If templates took parameters (so that you could pass data into them) I 
believe that would resolve the use case, but that isn't something we support.  
Perhaps this should be a "Feature: function_template should take an optional 
hash of values to pass in to the template" or some such?

----------------------------------------
Bug #6492: Local ruby variables in templates are not available in "included" 
templates
https://projects.puppetlabs.com/issues/6492

Author: Peter Meier
Status: Needs design decision
Priority: Normal
Assignee: Nigel Kersten
Category: file
Target version: 
Affected Puppet version: 
Keywords: 
Branch: 


Given the following code:

<pre>
#some_template.erb
<%- [:foo, :bar].each do |state| %>
  <%= scope.function_template('some/other_template.erb') %>
<%- end %>

# some/other_template.erb
<%- if state == :foo %>
write something
<%- end %>
</pre>

You will have the error/problem that `state` is not defined.

There is a dirty workaround for this problem:

<pre>
#some_template.erb
<%- [:foo, :bar].each do |state| 
  scope.unsetvar('state')
  scope.setvar('state',state)
%>
  <%= scope.function_template('some/other_template.erb') %>
<%- end %>
</pre>

However, I think there should be either a shortcut to make the variable 
available in included templates or the variables should be present in the 
"included" template as local variables. Note that also assigning `state` to an 
instance variable does not work:

<pre>
#some_template.erb
<%- [:foo, :bar].each do |state| 
  @state = state
%>
  <%= scope.function_template('some/other_template.erb') %>
<%- end %>
</pre>




-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to