Re: erb template test if value in array

1,757 views
Skip to first unread message

jcbollinger

unread,
Aug 27, 2012, 2:26:06 PM8/27/12
to puppet...@googlegroups.com


On Tuesday, August 21, 2012 10:42:16 AM UTC-5, LTH wrote:
In an .erb template, I want to test if a value is in an array (and if yes do something).

I thought the way to do it might me something like:

<% if @testservers.include? @fqdn %>
environment = test
<% else %>
environment = production
<% end %>

However that blows up complaining that .include is an undefined function.


It will do so if @testservers is not an array (or, more properly, if it does not have a method named "include?").  Perhaps this will do what you want:

<% if (defined? @testservers) and (@testservers.class == 'Array') and (@testservers.include? @fqdn) %>

 
John

Reply all
Reply to author
Forward
0 new messages