[英]Phalcon PHP NativeArray accessing multidimensional array using Volt Template
I was able to add multi language support in Phalcon using the volt template. 我可以使用volt模板在Phalcon中添加多语言支持。
But I can't access phalcon multi dimensional NativeArray in volt. 但是我无法以伏特访问phalcon多维NativeArray。
Here is my getTranslation function: 这是我的getTranslation函数:
private function _getTranslation()
{
global $config;
if ( isset($config[$_SERVER['HTTP_HOST']]['language']) ) {
$language = $config[$_SERVER['HTTP_HOST']]['language'];
} else if ( $this->session->get('auth') ) {
$language = "pt";
} else {
//Ask browser what is the best language
$language = $this->request->getBestLanguage();
}
//Check if we have a translation file for that lang
if (file_exists(__DIR__ . "/../translations/".$language.".php")) {
require __DIR__ . "/../translations/".$language.".php";
} else {
// fallback to some default
require __DIR__ . "/../translations/en-US.php";
}
//Return a translation object
return new \Phalcon\Translate\Adapter\NativeArray(array(
"content" => $messages
));
}
Then I setvar: 然后我setvar:
$this->view->setVar("t", $this->_getTranslation());
Which will load a translation file with something like this: 它将加载具有以下内容的翻译文件:
$messages = array(
"pages" => array(
"index" => array(
"title" => "CREATE YOUR ACCOUNT TODAY",
"call_to_action" => "Join Now!",
"search_title" => "Find:",
"search_option" => "I Want To:",
"search_type" => "Type:",
"search_where" => "Located On:",
"search_button" => "GO",
)
);
In the volt template I would like to access something like 在伏特模板中,我想访问类似
$t['pages']['index']['call_to_action']
Which in volt could be: 伏特可能是:
<div class="call_to_action">{{ t._('pages').('index').('call_to_action') }}</div>
But this doesn't work! 但这不起作用!
Is there any way to access the NativeArray multi dimensional elements within volt template? 有什么方法可以访问伏特模板中的NativeArray多维元素?
Try this.. 尝试这个..
For more information refer twig documentation 有关更多信息,请参阅树枝文档
{{ dump(t['pages']['index']['call_to_action']) }}
Output Example: 输出示例:
string 'Join Now!' (length=9)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.