processwire / processwire-requests

ProcessWire feature requests.
39 stars 0 forks source link

add TemplateFile simple var setter #410

Open pine3ree opened 3 years ago

pine3ree commented 3 years ago

Hello Ryan, when using the wireRenderFile function, the TemplateFile instance is using the data($name, $value = null) function to set template vars. The (little) issue here is that when the $value argument is null data() it acts as a getter not as a setter. I would like to have a method that always act as a setter even for null value smt like setVar($name, $value) or assign($name, $value) and bypasses the set() logic same way as data() does.

// file templates/product-holder.php
// logic here
echo wireRenderFile('view/common/header.html.php', ($header_data ?? []) + $shared_data);
echo wireRenderFile('view/shop/product-list.html.php', [
    'products' => $products ?? new PageArray(),
    'customer' => $user->isLoggedIn() ? $user : null, 
] + $shared_data);
echo wireRenderFile('view/common/footer.html.php', ($footer_data ?? []) + $shared_data);

for instance in the example above in product-list.html.php I would like to check for the $user var without using isset(). Of course this is no big deal but technically it seems more appropriate that the code that assigns vars to the template file always acts as a setter no matter what kind of value is passed in.

kind regards