Reputation: 2452
What function can I use in PHP for class Smarty which reads a variable's value from the Smarty's config file?
Here's my code:
<?
session_start();
require('libs/Smarty.class.php');
$smarty = new Smarty;
$smarty->config_load("settings.conf");
include('settings.php');
include('meta.php');
$smarty->debugging = false;
$smarty->caching =false;
$smarty->cache_lifetime = 120;
include("categories.php");
include("manufacturers.php");
include("logos.php");
print_r($smarty->getConfigVariable("showCategories"));
close_database_session($dbconn);
//$smarty->display('index.tpl');
?>
Upvotes: 1
Views: 6192
Reputation: 11
smarty->configLoad(...)
produces a notice like
"Notice: function call 'config_load' is unknown or deprecated."
A workaround is putting an @ in front of the call like
@smarty->configLoad($cfgFile)
Upvotes: 1
Reputation: 1
Here is the simple way to get your smarty assigned config variables:
print_r
of your $smarty
object and note down your config variables.
Get those variables of say settings.conf
:
$category_title1 = $smarty->_config[0]['vars']['driving_license_category'];
You can then use as you like it in PHP.
Upvotes: 0
Reputation: 11
I did it using this code:
$templ->fetch('template_that_loads_config.tpl');
print_r($templ->_config[0]['vars']);
Upvotes: 1
Reputation: 816790
With get_config_vars()
(you have to load the configuration beforehand with config_load()
).
Example from the documentation:
// get loaded config template var #foo#
$myVar = $smarty->get_config_vars('foo');
// get all loaded config template vars
$all_config_vars = $smarty->get_config_vars();
Update (Smarty 3.0 RC1):
For Smarty 3.0 RC1 it is
$smarty->configLoad($config_file, $sections = null)
// and
$smarty->getConfigVariable($variable)
Note there is no official documentation yet but the methods available are listed in the included README file.
Upvotes: 4