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 include file in config.inc.php based on template option?

Skinning and designing Serendipity (CSS, HTML, Smarty)
User avatar
Don Chambers
Regular
 
Posts: 3079
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA

Postby Don Chambers » Sat Dec 31, 2011 6:48 pm

In config.inc.php, I want to do something like I would otherwise do in a tpl, such as:

Code: Select all
{if $template_option.file =='true'}
    {include file="myfile.php"}
{/if}


I might not actually include a file, I might just put a block of code at that point... the key question is can I evaluate a template option within config.inc.php? Is so, how? If so, is it enough of a performance impact that I should NOT do it even if I can?

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

Postby Timbalu » Mon Jan 02, 2012 3:22 pm

Hi Don

Is that still a remaining question?

Should be
Code: Select all
if($template_loaded_config['file']) { do something }
or
Code: Select all
if($template_loaded_config['file'] == 'true') { do something }
depending on your config.inc.php serendipity_loadThemeOptions() call having a 3rd param = booleanize boolean $template_config vars.

About the performance impact, it should not be that much more, as you already use a $template_config array to perform somehow.
Regards,
Ian

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

Postby garvinhicking » Mon Jan 02, 2012 5:15 pm

Hi!

Sure, you can use PHP's "include" command, and everything that works within config.inc.php also works in any other included file...

Regards,
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
Don Chambers
Regular
 
Posts: 3079
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA

Postby Don Chambers » Mon Jan 02, 2012 8:17 pm

[quote="Timbalu" depending on your config.inc.php serendipity_loadThemeOptions() call having a 3rd param = booleanize boolean $template_config vars.[/quote]


what? :?:

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

Postby Timbalu » Mon Jan 02, 2012 9:22 pm

;-)

At the end of config.inc.php (2k11) you can find these:
Code: Select all
$template_global_config = array('navigation' => true);
$template_loaded_config = serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option'], true);
serendipity_loadGlobalThemeOptions($template_config, $template_loaded_config, $template_global_config);

$template_config = the current default template configuration
$template_loaded_config = the final return array values, based on the saved s9y_options db table
$template_global_config = the global navigation and amount settings

The second, $template_loaded_config has a new third parameter (to stay backward compatible) set to true here, introduced with s9y 1.6, which turns template_config boolean vars (interpreted as strings) into real booleans for the output, e.g.
Code: Select all
     array(
        'var'           => 'sitenav_footer',
        'name'          => SITENAV_FOOTER,
        'type'          => 'boolean',
        'default'       => 'true'
    ),
can now be read by {if $template_option.sitenav_footer} blah {/if}
Regards,
Ian

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

Postby Don Chambers » Sun May 06, 2012 3:42 pm

Thanks to Iam's suggestions above, this works in my config.inc.php:
Code: Select all
if($template_loaded_config['include_file'] == 'true') {
   include ("config.file1.php");
} else {
   include ("config.file2.php");
}


However, within my included files (file1.php & file2.php), I want to set a variable equal to one of my template options within a function, but this is not working:
Code: Select all
$var = $template_loaded_config['text']


Is there a way to make $template_loaded_config available within a function of an included file?

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

Postby Timbalu » Sun May 06, 2012 5:23 pm

Don Chambers wrote:Is there a way to make $template_loaded_config available within a function of an included file?

Yes, load your php files at the end of your config.inc.php - after the $template_loaded_config var! :wink: ... and within a function you might need to hand it over:
Code: Select all
function xy($tlc) { $text = $tlc['text']; }
$foo = xy($template_loaded_config);
Regards,
Ian

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

Postby Don Chambers » Sun May 06, 2012 5:56 pm

included files are at the end of config.inc.php....

Lets say that one of those included files is file1.php. Within file1.php, I have something like this:

Code: Select all
function serendipity_plugin_api_pre_event_hook($event, &$bag, &$eventData, &$addData) {
    //blah blah blah
    // what I want to do is this, where $template_loaded_config['my_text'] is just a simple string:
    $eventData[$entryIdx]['extended'] = $template_loaded_config['my_text'];
}


I didn't write the above function, so I do not quite understand all of it... can you describe your answer using my example above?

Thanks!

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

Postby Timbalu » Sun May 06, 2012 6:45 pm

did you try and add it as global?
Code: Select all
function serendipity_plugin_api_pre_event_hook($event, &$bag, &$eventData, &$addData) {
    global $template_loaded_config;
    // blah blah
    $eventData[$entryIdx]['extended'] = $template_loaded_config['my_text'];
Regards,
Ian

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

Postby Don Chambers » Sun May 06, 2012 8:23 pm

yes, that was the first thing I tried.... did not work.

EDIT: making it global inside config.inc.php AND the function worked.... any downside to that?

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

Postby Timbalu » Mon May 07, 2012 10:44 am

No, not really downsize... as you could hook the $template_loaded_config into the xxxData stream, somehow...
Code: Select all
serendipity_plugin_api::hook_event('backend_display', $template_loaded_config);
Regards,
Ian



Return to Themes

Who is online

Users browsing this forum: No registered users and 1 guest