I just wondered to see Bulletproof using boolean vars as string.
Is there is anything bad setting $template_option vars to real booleans?
template_options boolean
template_options boolean
Regards,
Ian
Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Ian
Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Re: template_options boolean
Huh? There are two template options which are strings – addthisaccount and sidenav_sidebar_title. What do you mean?Timbalu wrote:I just wondered to see Bulletproof using boolean vars as string.
Is there is anything bad setting $template_option vars to real booleans?
YL
Re: template_options boolean
No I dont mean strings. I really meant the booleans. Just as an example:
there are lots of them.
Type is set to boolean, but it's value is set to 'true', which is a string. If you need to check this value in the tpls, you have to check {if $template_option.footercategories == 'true'}. A real boolean could be checked by {if $template_option.footercategories}. I wondered why this was kind of necessary or overseen all the years.
Btw., the option table stores them as they are by value, booleans like 1/, strings as 'true/false'.
Code: Select all
array(
'var' => 'footercategories',
'name' => FOOTER_CATEGORIES,
'type' => 'boolean',
'default' => 'true',
),
Type is set to boolean, but it's value is set to 'true', which is a string. If you need to check this value in the tpls, you have to check {if $template_option.footercategories == 'true'}. A real boolean could be checked by {if $template_option.footercategories}. I wondered why this was kind of necessary or overseen all the years.
Btw., the option table stores them as they are by value, booleans like 1/, strings as 'true/false'.
Regards,
Ian
Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Ian
Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Re: template_options boolean
I remember these originally being strings and us switching them to boolean to save some … erm … bytes? I wasn't even aware that this was the wrong usage of the boolean type, so it was probably a combination of us now knowing better and the "real" coders not checking on us.Timbalu wrote:I wondered why this was kind of necessary or overseen all the years.
Can you give us a code example of how it's properly to be used in config.inc.php and .tpl files?
YL
Re: template_options boolean
Thats easy..., do not use quotes in case of booleans
Boolean true is 1, false is not set, so smarty can handle {if $foo} same as {if $foo === true}, {if !$foo} same as {if $foo === false}, but not {if $foo == 'true'} any more.
I dont think bulletproof needs to be changed because of that, I only noticed this by my own template, based on BP. Maybe its just worth to know for future versions.
Code: Select all
'type' => 'boolean',
'default' => true,
I dont think bulletproof needs to be changed because of that, I only noticed this by my own template, based on BP. Maybe its just worth to know for future versions.
Regards,
Ian
Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Ian
Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Re: template_options boolean
Yes, that's what I was thinking about – future template rather than versions. Thanks for clearing it up.Timbalu wrote:Maybe its just worth to know for future versions.
YL
-
- Regular
- Posts: 3652
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
Re: template_options boolean
I'm nearly certain {if $template_option.footercategories} works too.
=Don=
Re: template_options boolean
Back to start! I am sorry to say, this is not true (seeing only the template_config array). I now discovered booleans are set there to true or false as text. And as the template_loaded_config array, which is build by the option table values, is the one assigning those vars (somewhere) to smarty, these vars are strings in our templates, which is different to core or plugin assigned vars mostly carrying real booleans.Timbalu wrote:Btw., the option table stores them as they are by value, booleans like 1/, strings as 'true/false'.
Garvin, is there a way to proceed with real booleans here, like get the template_loaded_config array parsed by the serendipity_db_bool() function, or have I to revert my changes?
Regards,
Ian
Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Ian
Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: template_options boolean
Hi!
I thought that there should be a handler that converted boolean types using serendipity_db_bool() for template variables as well, just for plugin variables. I haven't checked, but if that is not the case, the core code should be changed to use serendipity_db_bool() on those conf items that have 'boolean' set as their type.
Regard,s
Garvin
I thought that there should be a handler that converted boolean types using serendipity_db_bool() for template variables as well, just for plugin variables. I haven't checked, but if that is not the case, the core code should be changed to use serendipity_db_bool() on those conf items that have 'boolean' set as their type.
Regard,s
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Re: template_options boolean
The type boolean is not available, since we are talking about the serendipity_loadThemeOptions() returning the option table $template_vars array. As a very hacky workaround I did this.
Hopefully it can be done better.
There still is the issue with the delay (of another reload) - even in this case - between $template_config (the real configs array) and $template_loaded_config (the options table array), which is bad to be left. This only produces confusion by none advanced users until they learned to submit twice.
Code: Select all
foreach($template_vars AS $k => $v) {if($v == 'true' || $v == 'false') {$template_vars[$k] = serendipity_db_bool($v);}}
There still is the issue with the delay (of another reload) - even in this case - between $template_config (the real configs array) and $template_loaded_config (the options table array), which is bad to be left. This only produces confusion by none advanced users until they learned to submit twice.
Regards,
Ian
Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Ian
Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Re: template_options boolean
This will break theme compatibility, so we need some sort of $bc_bool=false mode as function parameter.
If we do not have this, bulletproof and all other themes using == 'true/false' will not work as they did before.
If we do not have this, bulletproof and all other themes using == 'true/false' will not work as they did before.
Regards,
Ian
Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Ian
Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian