本文整理汇总了PHP中modResource::getTemplateVarCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP modResource::getTemplateVarCollection方法的具体用法?PHP modResource::getTemplateVarCollection怎么用?PHP modResource::getTemplateVarCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modResource
的用法示例。
在下文中一共展示了modResource::getTemplateVarCollection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTemplateVariables
/**
* Get all the Template Variables for this Resource
* @return void
*/
public function getTemplateVariables()
{
if (method_exists('modResource', 'getTemplateVarCollection')) {
$tvObjs = modResource::getTemplateVarCollection($this->resource);
} else {
$tvObjs = $this->_getTemplateVars();
}
$tvs = array();
$categories = array();
/** @var modTemplateVar $tv */
foreach ($tvObjs as $tv) {
if ($tv instanceof modTemplateVar) {
$tvArray = $tv->toArray();
if (!empty($categories[$tvArray['category']])) {
$tvs[$categories[$tvArray['category']]][] = $tv;
} else {
if ($tvArray['category'] == 0) {
$tvs[$this->modx->lexicon('uncategorized')][] = $tv;
} else {
$cat = $tv->getOne('Category');
if ($cat instanceof modCategory) {
$categories[$tvArray['category']] = $cat->get('category');
$tvs[$categories[$tvArray['category']]][] = $tv;
}
}
}
}
}
$list = array();
if (count($tvs) > 0) {
$this->modx->loadClass('hmTvInputRenderer', $this->hm->config['classesPath'], true, true);
$renderer = new hmTvInputRenderer($this->hm);
foreach ($tvs as $categoryName => $categoryTemplateVariables) {
$tvList = array();
/** @var modTemplateVar $tv */
foreach ($categoryTemplateVariables as $tv) {
$tvList[] = $renderer->render($tv->get('display'), $tv);
}
$list[] = $this->hm->getTpl('fields/tvs/category', array('name' => $categoryName, 'collapsed' => !isset($notFirst) && count($tvs != 1) ? 'data-collapsed="false"' : 'data-collapsed="true"', 'tvs' => implode("\n", $tvList)));
// This makes sure the first section is opened if there are > 1 sections
$notFirst = true;
}
unset($notFirst);
}
$this->setPlaceholder('tvs', implode("\n", $list));
}