是否可以将变量放入配置文件中?

是否可以将变量放入配置文件中?

问题描述:

我使用smarty允许网站上使用不同的语言,到目前为止,该方法还可以。我将文本存储在不同部分的配置文件中。

I use smarty to allow different languages on my site, which works OK so far. I store the texts in config files in different sections.

但是然后有这样的句子:

But then there are sentences like this:

您有6封新邮件! em>,用德语 Sie haben 6 neue Mails!

现在数字前和数字后都有文字,从数据库加载的。而且我想将其放入配置文件中,然后自行加载数字。

Now there's text before the number and behind the number, which is loaded from the database. And I would like to put it into the config file and just load the number on its own.

所以我将其保存在 text.conf中

so I have this in my "text.conf"

[en]
mail_count = "You have $NUMBER new mails!"
[de]
mail_count = "Sie haben $NUMBER neue Mails!"

而这在我的 show_text.php中

and this in my "show_text.php"

$smarty->assign('NUMBER', 6);

是否可能这样?也许有了Smarty 3.0?

Is something like this possible? Maybe with Smarty 3.0?

在此先感谢
BH

Thanks in advance, BH

读取配置文件时,您需要使用

When reading the config file, you need to open it using

$cfg = $smarty->fetch('path/to/file');

之后,您将整个文件内容包含在$ cfg变量中,并替换了{$ NUMBER}。

After that you have the whole files content ind the $cfg variable, with {$NUMBER} replaced.