I''ve got the following template. <VirtualHost *:80> DocumentRoot /web/<%= name %> ServerName <%= name %>.example.com <% unless server_alias.empty? %><%= server_alias %><% end %> </VirtualHost> At times I need to pass an empty variable. vhosts { ahost: document_root => "/var/www/html/", server_alias => "", } The problem I''m trying to fix is to stop printing a new line when the variable is empty. I know very little Ruby/erb but I''ve tried the line above and an "if empty chomp" and <% if server_alias.empty? %><%= server_alias -%><% else %><%server_alias %><% end %>. Anyone know how to stop the template from printing a blank line when a variable is empty? Thanks, Kent
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Friday 22 February 2008, Kenton Brede wrote:> I''ve got the following template. > > <VirtualHost *:80> > DocumentRoot /web/<%= name %> > ServerName <%= name %>.example.com > <% unless server_alias.empty? %><%= server_alias %><% end %> > </VirtualHost> > > > At times I need to pass an empty variable. > > vhosts { ahost: > document_root => "/var/www/html/", > server_alias => "", > } > > The problem I''m trying to fix is to stop printing a new line when the > variable is empty. I know very little Ruby/erb but I''ve tried the > line above and an "if empty chomp" and > <% if server_alias.empty? %><%= server_alias -%><% else %><%> server_alias %><% end %>. > > Anyone know how to stop the template from printing a blank line when a > variable is empty?I think you have to add the - to all %>, or at least to the last. Regards, DavidS - -- The primary freedom of open source is not the freedom from cost, but the free- dom to shape software to do what you want. This freedom is /never/ exercised without cost, but is available /at all/ only by accepting the very different costs associated with open source, costs not in money, but in time and effort. - -- http://www.schierer.org/~luke/log/20070710-1129/on-forks-and-forking -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFHvu4q/Pp1N6Uzh0URAnK1AJoD6T0WS+/IjRZ3FEAOZwNEz/9DuQCcDGpZ dP27A2UvS3Bx0MYKaK5nXF8=gCs8 -----END PGP SIGNATURE-----
On 22/02/2008, David Schmitt <david@schmitt.edv-bus.at> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > > On Friday 22 February 2008, Kenton Brede wrote: > > I''ve got the following template. > > > > <VirtualHost *:80> > > DocumentRoot /web/<%= name %> > > ServerName <%= name %>.example.com > > <% unless server_alias.empty? %><%= server_alias %><% end %> > > </VirtualHost> > > > > > > At times I need to pass an empty variable. > > > > vhosts { ahost: > > document_root => "/var/www/html/", > > server_alias => "", > > } > > > > The problem I''m trying to fix is to stop printing a new line when the > > variable is empty. I know very little Ruby/erb but I''ve tried the > > line above and an "if empty chomp" and > > <% if server_alias.empty? %><%= server_alias -%><% else %><%> > server_alias %><% end %>. > > > > Anyone know how to stop the template from printing a blank line when a > > variable is empty? > > > > I think you have to add the - to all %>, or at least to the last.I had tried that but unfortunately when the variable is present then it doesn''t print the newline so I end up with: ServerAlias testing.example.com</VirtualHost> instead of ServerAlias testing.example.com </VirtualHost> This is a maddening little problem :) Thanks, Kent
Try putting your conditional on multiple lines, with the -%> on the lines you don''t want to show up <% unless server_alias.empty? -%> <%= server_alias %> <% end -%> -Andrew On Feb 22, 2008, at 11:02 PM, Kenton Brede wrote:> On 22/02/2008, David Schmitt <david@schmitt.edv-bus.at> wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> >> On Friday 22 February 2008, Kenton Brede wrote: >>> I''ve got the following template. >>> >>> <VirtualHost *:80> >>> DocumentRoot /web/<%= name %> >>> ServerName <%= name %>.example.com >>> <% unless server_alias.empty? %><%= server_alias %><% end %> >>> </VirtualHost> >>> >>> >>> At times I need to pass an empty variable. >>> >>> vhosts { ahost: >>> document_root => "/var/www/html/", >>> server_alias => "", >>> } >>> >>> The problem I''m trying to fix is to stop printing a new line when >>> the >>> variable is empty. I know very little Ruby/erb but I''ve tried the >>> line above and an "if empty chomp" and >>> <% if server_alias.empty? %><%= server_alias -%><% else %><%>>> server_alias %><% end %>. >>> >>> Anyone know how to stop the template from printing a blank line >>> when a >>> variable is empty? >> >> >> >> I think you have to add the - to all %>, or at least to the last. > > I had tried that but unfortunately when the variable is present then > it doesn''t print the newline so I end up with: > > ServerAlias testing.example.com</VirtualHost> > > instead of > > ServerAlias testing.example.com > </VirtualHost> > > This is a maddening little problem :) > Thanks, > Kent > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users