Page 1 of 1
include file in config.inc.php based on template option?
Posted: Sat Dec 31, 2011 5:48 pm
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?
Re: include file in config.inc.php based on template option?
Posted: Mon Jan 02, 2012 2:22 pm
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.
Re: include file in config.inc.php based on template option?
Posted: Mon Jan 02, 2012 4:15 pm
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
Re: include file in config.inc.php based on template option?
Posted: Mon Jan 02, 2012 7:17 pm
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?

Re: include file in config.inc.php based on template option?
Posted: Mon Jan 02, 2012 8:22 pm
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}
Re: include file in config.inc.php based on template option?
Posted: Sun May 06, 2012 3:42 pm
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?
Re: include file in config.inc.php based on template option?
Posted: Sun May 06, 2012 5:23 pm
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!

... 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);
Re: include file in config.inc.php based on template option?
Posted: Sun May 06, 2012 5:56 pm
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!
Re: include file in config.inc.php based on template option?
Posted: Sun May 06, 2012 6:45 pm
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'];
Re: include file in config.inc.php based on template option?
Posted: Sun May 06, 2012 8:23 pm
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?
Re: include file in config.inc.php based on template option?
Posted: Mon May 07, 2012 10:44 am
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);