[Puppet Users] Re: How to increment variable in erb template ?

Krzysztof Wilczynski
Tue, 24 Apr 2012 14:09:44 -0000

Hi,

On Tuesday, 24 April 2012 14:38:28 UTC+1, AnOnJoe wrote:
>
> Hi'',
>
> I''m looking for a way to increment variable in template (erb
file).
>
> I tried this, but it didn''t work
>
> Compteur <%= compteur %>
>> <% compteur = compteur + 1 %>
>> Compteur <%= compteur %>
>>
>
> I''ve got this error :
>
>> Error 400 on SERVER: Failed to parse template test/test.erb: undefined
>> method `+'' for nil:NilClass
>>
>
Would that help?

 kwilczynski@desktop:~$ irb
irb(main):001:0> require ''erb''
=> true
irb(main):002:0> t = ERB.new <<-EOS
irb(main):003:0" <%= c = c ? c += 1 : 1 %>
irb(main):004:0" EOS
=> #<ERB:0x7f2cde07cbe8 @safe_level=nil, @src="_erbout =
'''';
_erbout.concat(( c = c ? c += 1 : 1 ).to_s); _erbout.concat \"\\n\"\n;
_erbout", @filename=nil>
irb(main):005:0> t.result(binding)
=> "1\n"
irb(main):006:0> t.result(binding)
=> "2\n"
irb(main):007:0> t.result(binding)
=> "3\n"
irb(main):008:0>

KW

--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To view this discussion on the web visit