gruntwork-io / boilerplate

A tool for generating files and folders ("boilerplate") from a set of templates
https://www.gruntwork.io
Mozilla Public License 2.0
160 stars 12 forks source link

Add support for boolean variable type to better handle if statements. #5

Closed josh-padnick closed 7 years ago

josh-padnick commented 7 years ago

In the README, the following files are suggested as examples:

boilerplate.yml

variables:
  ...
  - name: ShowLogo
    prompt: Should the webiste show the logo?
    default: true

index.html

<html>
   ...
  <body>
    ...
    {{if .ShowLogo}}<img src="logo.png">{{end}}
  </body>
</html>

But as written, this example will always render the <img> tag because boilerplate doesn't yet support any variable type other than string. In this case, a boolean type would allow this to work.

As a string, the only way to get the if statement to be false is for .ShowLogo to be empty, which requires that no default value be defined.

brikis98 commented 7 years ago

I'm going to close this as a duplicate of #9.

FWIW, the current work around for booleans is to compare the variable to the string "true". E.g.:

{{ if eq .ShowLogo "true" }} 
  (do something)
{{ end }}