include file in config.inc.php based on template option?

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

include file in config.inc.php based on template option?

Post by Don Chambers »

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?
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: include file in config.inc.php based on template option?

Post by Timbalu »

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

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: include file in config.inc.php based on template option?

Post by garvinhicking »

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/
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: include file in config.inc.php based on template option?

Post by Don Chambers »

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


what? :?:
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: include file in config.inc.php based on template option?

Post by Timbalu »

;-)

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

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: include file in config.inc.php based on template option?

Post by Don Chambers »

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?
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: include file in config.inc.php based on template option?

Post by Timbalu »

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

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: include file in config.inc.php based on template option?

Post by Don Chambers »

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!
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: include file in config.inc.php based on template option?

Post by Timbalu »

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

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: include file in config.inc.php based on template option?

Post by Don Chambers »

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?
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: include file in config.inc.php based on template option?

Post by Timbalu »

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

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Post Reply