The Serendipity Handbook

You can now read the (german) handbook here: PDF - https://github.com/s9y/Book (LaTeX source).

Forum-Information

Before posting about errors, make sure that the answer cannot already be found in our FAQ or by searching this forum!
Posting is restricted to registered users (registering is free and simple!) due to recent spam attacks. When having trouble with this board, contact garvin(-at)s9y(-dot)org.

Board index Themes template_options boolean

Skinning and designing Serendipity (CSS, HTML, Smarty)
User avatar
Timbalu
Regular
 
Posts: 2691
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Thu Aug 18, 2011 8:09 pm

I just wondered to see Bulletproof using boolean vars as string.
Is there is anything bad setting $template_option vars to real booleans?
Regards,
Ian

User avatar
yellowled
Regular
 
Posts: 4936
Joined: Fri Jan 13, 2006 12:46 pm
Location: Eutin, Germany

Postby yellowled » Thu Aug 18, 2011 10:57 pm

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?

Huh? There are two template options which are strings – addthisaccount and sidenav_sidebar_title. What do you mean?

YL

User avatar
Timbalu
Regular
 
Posts: 2691
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Fri Aug 19, 2011 9:45 am

No I dont mean strings. I really meant the booleans. Just as an example:
Code: Select all
    array(
        'var'           => 'footercategories',
        'name'          => FOOTER_CATEGORIES,
        'type'          => 'boolean',
        'default'       => 'true',
    ),
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'.
Regards,
Ian

User avatar
yellowled
Regular
 
Posts: 4936
Joined: Fri Jan 13, 2006 12:46 pm
Location: Eutin, Germany

Postby yellowled » Fri Aug 19, 2011 10:44 am

Timbalu wrote:I wondered why this was kind of necessary or overseen all the years.

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.

Can you give us a code example of how it's properly to be used in config.inc.php and .tpl files?

YL

User avatar
Timbalu
Regular
 
Posts: 2691
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Fri Aug 19, 2011 11:09 am

Thats easy..., do not use quotes in case of booleans
Code: Select all
'type'          => 'boolean',
'default'       => true,

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.
Regards,
Ian

User avatar
yellowled
Regular
 
Posts: 4936
Joined: Fri Jan 13, 2006 12:46 pm
Location: Eutin, Germany

Postby yellowled » Fri Aug 19, 2011 1:11 pm

Timbalu wrote:Maybe its just worth to know for future versions.

Yes, that's what I was thinking about – future template rather than versions. Thanks for clearing it up.

YL

User avatar
Don Chambers
Regular
 
Posts: 3079
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA

Postby Don Chambers » Fri Aug 19, 2011 3:22 pm

I'm nearly certain {if $template_option.footercategories} works too.

User avatar
Timbalu
Regular
 
Posts: 2691
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Fri Aug 19, 2011 8:20 pm

Timbalu wrote:Btw., the option table stores them as they are by value, booleans like 1/, strings as 'true/false'.

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.

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

User avatar
garvinhicking
Core Developer
 
Posts: 28971
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany

Postby garvinhicking » Sat Aug 20, 2011 9:52 am

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
# 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/

User avatar
Timbalu
Regular
 
Posts: 2691
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Sat Aug 20, 2011 11:17 am

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.
Code: Select all
foreach($template_vars AS $k => $v) {if($v == 'true' || $v == 'false') {$template_vars[$k] = serendipity_db_bool($v);}}
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.
Regards,
Ian

User avatar
Timbalu
Regular
 
Posts: 2691
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Sat Aug 20, 2011 2:19 pm

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.
Regards,
Ian



Return to Themes

Who is online

Users browsing this forum: No registered users and 1 guest