How do I call a variable from my manifest inside, while of another variable in a template.erb file?
This is what I've tried to do:
<%= food[<%= menu %>] %>
How do I get this to work?
How do I call a variable from my manifest inside, while of another variable in a template.erb file?
This is what I've tried to do:
<%= food[<%= menu %>] %>
How do I get this to work?
You just use the variable, as is:
<%= food[menu] %>
You're already in "Ruby code space" within the ERB expansion, so you can use Ruby code as you normally would.
Referring to the Puppet 4.5 Embedded Ruby (ERB) template syntax section on Accessing Puppet Variables, there are 2 forms of variable access:
From the example in the question, there's not enough information to accurately determine the origin of the food variable. This question assumes that it's the result of processing an array or hash manifest variable. If food is the manifest variable, itself, it should be prefaced with @, as such:
<%= @food[menu] %>
If the manifest variable is foods, and the food variable is an element of the enumerable (Array or Hash), it would be used as such:
<%= @foods.each do |food| %>
<%= @food[menu] %>
<% end %>
Stick with the documented methods of accessing the manifest variable, and you can use it in your template exactly as you would within traditional Ruby code.
@var form.