本文整理汇总了PHP中FrontendTemplate::assign方法的典型用法代码示例。如果您正苦于以下问题:PHP FrontendTemplate::assign方法的具体用法?PHP FrontendTemplate::assign怎么用?PHP FrontendTemplate::assign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FrontendTemplate
的用法示例。
在下文中一共展示了FrontendTemplate::assign方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parsePagination
//.........这里部分代码省略.........
// as long as we are below page 5 we should show all pages starting from 1
if ($this->pagination['requested_page'] <= 6) {
// init vars
$pagesStart = 1;
$pagesEnd = $this->pagination['num_pages'] >= 6 ? 7 : $this->pagination['num_pages'];
// show last pages
if ($this->pagination['num_pages'] > 6) {
$showLastPages = true;
}
} elseif ($this->pagination['requested_page'] >= $this->pagination['num_pages'] - 4) {
// init vars
$pagesStart = $this->pagination['num_pages'] - 5;
$pagesEnd = $this->pagination['num_pages'];
// show first pages
if ($this->pagination['num_pages'] > 5) {
$showFirstPages = true;
}
} else {
// init vars
$pagesStart = $this->pagination['requested_page'] - 2;
$pagesEnd = $this->pagination['requested_page'] + 2;
$showFirstPages = true;
$showLastPages = true;
}
// show previous
if ($this->pagination['requested_page'] > 1) {
// build URL
if ($useQuestionMark) {
$URL = $this->pagination['url'] . '?page=' . ($this->pagination['requested_page'] - 1);
} else {
$URL = $this->pagination['url'] . '&page=' . ($this->pagination['requested_page'] - 1);
}
// set
$pagination['show_previous'] = true;
$pagination['previous_url'] = $URL;
}
// show first pages?
if ($showFirstPages) {
// init var
$pagesFirstStart = 1;
$pagesFirstEnd = 1;
// loop pages
for ($i = $pagesFirstStart; $i <= $pagesFirstEnd; $i++) {
// build URL
if ($useQuestionMark) {
$URL = $this->pagination['url'] . '?page=' . $i;
} else {
$URL = $this->pagination['url'] . '&page=' . $i;
}
// add
$pagination['first'][] = array('url' => $URL, 'label' => $i);
}
}
// build array
for ($i = $pagesStart; $i <= $pagesEnd; $i++) {
// init var
$current = $i == $this->pagination['requested_page'];
// build URL
if ($useQuestionMark) {
$URL = $this->pagination['url'] . '?page=' . $i;
} else {
$URL = $this->pagination['url'] . '&page=' . $i;
}
// add
$pagination['pages'][] = array('url' => $URL, 'label' => $i, 'current' => $current);
}
// show last pages?
if ($showLastPages) {
// init var
$pagesLastStart = $this->pagination['num_pages'];
$pagesLastEnd = $this->pagination['num_pages'];
// loop pages
for ($i = $pagesLastStart; $i <= $pagesLastEnd; $i++) {
// build URL
if ($useQuestionMark) {
$URL = $this->pagination['url'] . '?page=' . $i;
} else {
$URL = $this->pagination['url'] . '&page=' . $i;
}
// add
$pagination['last'][] = array('url' => $URL, 'label' => $i);
}
}
// show next
if ($this->pagination['requested_page'] < $this->pagination['num_pages']) {
// build URL
if ($useQuestionMark) {
$URL = $this->pagination['url'] . '?page=' . ($this->pagination['requested_page'] + 1);
} else {
$URL = $this->pagination['url'] . '&page=' . ($this->pagination['requested_page'] + 1);
}
// set
$pagination['show_next'] = true;
$pagination['next_url'] = $URL;
}
// multiple pages
$pagination['multiple_pages'] = $pagination['num_pages'] == 1 ? false : true;
// assign pagination
$this->tpl->assign('pagination', $pagination);
}
示例2: getNavigationHTML
/**
* Get navigation HTML
*
* @return string
* @param string[optional] $type The type of navigation the HTML should be build for.
* @param int[optional] $parentId The parentID to start of.
* @param int[optional] $depth The maximum depth to parse.
* @param array[optional] $excludeIds PageIDs to be excluded.
* @param bool[optional] $includeChildren Children can be included regardless of whether we're at the current page.
* @param int[optional] $depthCounter A counter that will hold the current depth.
*/
public static function getNavigationHTML($type = 'page', $parentId = 0, $depth = null, $excludeIds = array(), $includeChildren = false, $depthCounter = 1)
{
// get navigation
$navigation = self::getNavigation();
// meta-navigation is requested but meta isn't enabled
if ($type == 'meta' && !FrontendModel::getModuleSetting('pages', 'meta_navigation', true)) {
return '';
}
// validate
if (!isset($navigation[$type])) {
throw new FrontendException('This type (' . $type . ') isn\'t a valid navigation type. Possible values are: page, footer, meta.');
}
if (!isset($navigation[$type][$parentId])) {
throw new FrontendException('The parent (' . $parentId . ') doesn\'t exists.');
}
// special construction to merge home with it's immediate children
$mergedHome = false;
while (true) {
// loop elements
foreach ($navigation[$type][$parentId] as $id => $page) {
// home is a special item, it should live on the same depth
if ($page['page_id'] == 1 && !$mergedHome) {
// extra checks otherwise exceptions will wbe triggered.
if (!isset($navigation[$type][$parentId]) || !is_array($navigation[$type][$parentId])) {
$navigation[$type][$parentId] = array();
}
if (!isset($navigation[$type][$page['page_id']]) || !is_array($navigation[$type][$page['page_id']])) {
$navigation[$type][$page['page_id']] = array();
}
// add children
$navigation[$type][$parentId] = array_merge($navigation[$type][$parentId], $navigation[$type][$page['page_id']]);
// mark as merged
$mergedHome = true;
// restart loop
continue 2;
}
// not hidden
if ($page['hidden']) {
unset($navigation[$type][$parentId][$id]);
continue;
}
// some ids should be excluded
if (in_array($page['page_id'], (array) $excludeIds)) {
unset($navigation[$type][$parentId][$id]);
continue;
}
// if the item is in the selected page it should get an selected class
if (in_array($page['page_id'], self::$selectedPageIds)) {
$navigation[$type][$parentId][$id]['selected'] = true;
} else {
$navigation[$type][$parentId][$id]['selected'] = false;
}
// add nofollow attribute if needed
if ($page['no_follow']) {
$navigation[$type][$parentId][$id]['nofollow'] = true;
} else {
$navigation[$type][$parentId][$id]['nofollow'] = false;
}
// has children and is selected and is desired?
if (isset($navigation[$type][$page['page_id']]) && $page['page_id'] != 1 && ($navigation[$type][$parentId][$id]['selected'] == true || $includeChildren) && ($depth == null || $depthCounter + 1 <= $depth)) {
$navigation[$type][$parentId][$id]['children'] = self::getNavigationHTML($type, $page['page_id'], $depth, $excludeIds, $includeChildren, $depthCounter + 1);
} else {
$navigation[$type][$parentId][$id]['children'] = false;
}
// add parent id
$navigation[$type][$parentId][$id]['parent_id'] = $parentId;
// add depth
$navigation[$type][$parentId][$id]['depth'] = $depth;
// set link
$navigation[$type][$parentId][$id]['link'] = FrontendNavigation::getURL($page['page_id']);
// is this an internal redirect?
if (isset($page['redirect_page_id']) && $page['redirect_page_id'] != '') {
$navigation[$type][$parentId][$id]['link'] = FrontendNavigation::getURL((int) $page['redirect_page_id']);
}
// is this an external redirect?
if (isset($page['redirect_url']) && $page['redirect_url'] != '') {
$navigation[$type][$parentId][$id]['link'] = $page['redirect_url'];
}
}
// break the loop (it is only used for the special construction with home)
break;
}
// create template
$tpl = new FrontendTemplate(false);
// assign navigation to template
$tpl->assign('navigation', $navigation[$type][$parentId]);
// return parsed content
return $tpl->getContent(self::$templatePath, true, true);
}
示例3: getTemplateContent
/**
* Returns the content from a given template
*
* @return string
* @param string $template The template to use.
* @param array[optional] $variables The variabled to assign.
*/
private static function getTemplateContent($template, $variables = null)
{
// new template instance
$tpl = new FrontendTemplate(false);
// set some options
$tpl->setForceCompile(true);
// variables were set
if (!empty($variables)) {
$tpl->assign($variables);
}
// grab the content
$content = $tpl->getContent($template);
// replace internal links/images
$search = array('href="/', 'src="/');
$replace = array('href="' . SITE_URL . '/', 'src="' . SITE_URL . '/');
$content = str_replace($search, $replace, $content);
// require CSSToInlineStyles
require_once 'external/css_to_inline_styles.php';
// create instance
$cssToInlineStyles = new CSSToInlineStyles();
// set some properties
$cssToInlineStyles->setHTML($content);
$cssToInlineStyles->setUseInlineStylesBlock(true);
$cssToInlineStyles->setEncoding(SPOON_CHARSET);
// return the content
return (string) $cssToInlineStyles->convert();
}