FAQ
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
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/UJeLGDu-GxAJ.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Search Discussions

  • Krzysztof Wilczynski at Apr 24, 2012 at 2:10 pm
    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 https://groups.google.com/d/msg/puppet-users/-/RTEW8ohAolsJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • AnOnJoe at Apr 24, 2012 at 2:18 pm
    I've got it :

    Compteur <%= compteur %>
    *<% compteur = compteur.to_i -%>*
    <% compteur += 1 -%>
    Compteur <%= compteur %>

    Le mardi 24 avril 2012 15:38:28 UTC+2, AnOnJoe a écrit :
    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
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/7uZXvneHYQkJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Krzysztof Wilczynski at Apr 24, 2012 at 3:41 pm
    Hi,

    \o/

    KW
    On Tuesday, 24 April 2012 15:18:56 UTC+1, AnOnJoe wrote:

    I've got it :

    Compteur <%= compteur %>
    *<% compteur = compteur.to_i -%>*
    <% compteur += 1 -%>
    Compteur <%= compteur %>

    Le mardi 24 avril 2012 15:38:28 UTC+2, AnOnJoe a écrit :
    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
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/w1e5oy4P_8sJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedApr 24, '12 at 1:40p
activeApr 24, '12 at 3:41p
posts4
users2
websitepuppetlabs.com

2 users in discussion

AnOnJoe: 2 posts Krzysztof Wilczynski: 2 posts

People

Translate

site design / logo © 2022 Grokbase