Jump to content

Bug when passing numeric zero to template


helmut2509
 Share

Recommended Posts

Hello,

I just found out that,  when passing a (numeric) zero with "$view->myVar=0" to a template then the corresponding template variable $this->myVar is empty, it has no value.

This even occurs when I convert the value to a string: (string) 0

Strings and numeric values other than zero are handled correctly. 

I think this is a bug which should be fixed?!

 

regards, Helmut

Link to comment
Share on other sites

11 minutes ago, helmut2509 said:

Hello,

I just found out that,  when passing a (numeric) zero with "$view->myVar=0" to a template then the corresponding template variable $this->myVar is empty, it has no value.

This even occurs when I convert the value to a string: (string) 0

Strings and numeric values other than zero are handled correctly. 

I think this is a bug which should be fixed?!

 

regards, Helmut

Please open an issue at:   https://github.com/processwire/processwire-issues

Link to comment
Share on other sites

5 hours ago, helmut2509 said:

I just found out that,  when passing a (numeric) zero with "$view->myVar=0" to a template

What is $view? The PW core does not have the concept of a view that variables are passed to - there are just template files where the API variables are available.

I think this is not a core issue but perhaps you are using some third-party templating module in which case you should raise this in the module's support thread.

Link to comment
Share on other sites

Assuming you use TemplateFile ? This works as it should, variables are passed as is:

$tpl = new TemplateFile("_tpl.php");
$tpl->myVar1 = 0;
$tpl->set("myVar2", 1);
$content .= $tpl->render();

in _tpl.php

echo $myVar1;
echo $myVar2;

Outputs: 01

Link to comment
Share on other sites

17 hours ago, Robin S said:

What is $view? The PW core does not have the concept of a view that variables are passed to - there are just template files where the API variables are available.

I think this is not a core issue but perhaps you are using some third-party templating module in which case you should raise this in the module's support thread.

 

21 hours ago, dragan said:

you pass it via API to a template or a page? In case of the latter, I can't reproduce that.

$view is an instance of 

 \ProcessWire\TemplateFile
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...