Issue #22121 has been updated by Yoann Le Touche.

At the start of the section you have the short version of the explanation 
telling you to test if @variable is nil

> Short version: When testing for undefinedness, check whether the instance 
> variable (@variable) is nil – if the corresponding Puppet variable is either 
> undefined or explicitly set to undef, the instance variable will reliably 
> have a value of nil.
> 
> This only works for local variables, so if you need to test variables from 
> other scopes, you must copy them to local scope in the manifest before 
> evaluating the template:

    # manifest:
    $in_var = $outside_scope::outside_var

    # template:
    <% if @in_var %>
    outside_var has <%= @in_var %> value
    <% end %>

The long version gives you the why in detail.


----------------------------------------
Bug #22121: Documentation about testing for existence of variable in template 
is subtly wrong
https://projects.puppetlabs.com/issues/22121#change-98324

* Author: Thomas Vander Stichele
* Status: Closed
* Priority: Normal
* Assignee: Yoann Le Touche
* Category: documentation
* Target version: 
* Affected Puppet version: 
* Keywords: template, test, variable
* Branch: 
----------------------------------------
http://docs.puppetlabs.com/guides/templating.html

If the variable is defined but false, if @variable is false just the same.

So using @ cannot be used purely to test definedness.

In my template, I worked around it like this:

<% if @require_valid_user == false -%>
require_valid_user = false
<% elsif @require_valid_user == true -%>
require_valid_user = true
<% else -%>
; require_valid_user = false
<% end -%>

I suggest updating the docs at least, or providing a real way to test for 
definedness-but-nothing-else.


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to