Hey, I''d like to do something like this in my template: <%= if has_variable?(''some_variable'') then %><%= some_variable%><% else %>default<% end %> http://reductivelabs.com/trac/puppet/wiki/PuppetTemplating talks about conditionals, but not so much about if/else. Any suggestions? Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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 -~----------~----~----~----~------~----~------~--~---
Gary, The templates are using standard ERB, which essentially gives you the ability to do arbitrary conditional logic using ruby. Anything between <% %> is logic code and <%= %> is evaluated and printed. <% if condition %> <%= print_this %> <% else %> default <% end %> Play with ERB, it is very flexible. On Wed, Oct 15, 2008 at 6:24 PM, Gary Richardson <gary.richardson@gmail.com>wrote:> Hey, > > I''d like to do something like this in my template: > > <%= if has_variable?(''some_variable'') then %><%= some_variable%><% else > %>default<% end %> > > http://reductivelabs.com/trac/puppet/wiki/PuppetTemplating talks about > conditionals, but not so much about if/else. > > Any suggestions? > > Thanks! > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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 -~----------~----~----~----~------~----~------~--~---
Thanks, that got it going for me. I don''t know if there was a typo in my block of code, but it didn''t work for the first time around. On Wed, Oct 15, 2008 at 6:05 PM, Andrew Shafer <andrew@reductivelabs.com>wrote:> > Gary, > > The templates are using standard ERB, which essentially gives you the > ability to do arbitrary conditional logic using ruby. > > Anything between <% %> is logic code and <%= %> is evaluated and printed. > > <% if condition %> > <%= print_this %> > <% else %> > default > <% end %> > > Play with ERB, it is very flexible. > > > > > On Wed, Oct 15, 2008 at 6:24 PM, Gary Richardson < > gary.richardson@gmail.com> wrote: > >> Hey, >> >> I''d like to do something like this in my template: >> >> <%= if has_variable?(''some_variable'') then %><%= some_variable%><% else >> %>default<% end %> >> >> http://reductivelabs.com/trac/puppet/wiki/PuppetTemplating talks about >> conditionals, but not so much about if/else. >> >> Any suggestions? >> >> Thanks! >> >> >> > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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 -~----------~----~----~----~------~----~------~--~---