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

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
hostclass :class do
  items = scope.lookupvar('items_list')
  items.each do |item|
    file("/etc/init.d/#{item}",
         :content => template(['class/item_init.erb']))
  end
end

Having this class written in Ruby DSL, how do I properly reference the item variable in the template? I tried <%= item %>, <%= @item %>, <%= scope.lookupvar('item')%> but none of them work - they all return nil.

UPD

I've found out that it works if inside the loop I define $item_name = item and then reference it as $item_name in the template.

share|improve this question
up vote 0 down vote accepted

I've found out that it works if inside the loop I define $item_name = item and then reference it as $item_name in the template.

share|improve this answer

Your Answer

 
discard

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.