本文整理汇总了PHP中Smarty_Internal_Template::assign方法的典型用法代码示例。如果您正苦于以下问题:PHP Smarty_Internal_Template::assign方法的具体用法?PHP Smarty_Internal_Template::assign怎么用?PHP Smarty_Internal_Template::assign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Smarty_Internal_Template
的用法示例。
在下文中一共展示了Smarty_Internal_Template::assign方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smarty_block_image
/**
* Image block
*
* @param array $params
* @param string $content
* @param Smarty_Internal_Template $smarty
* @param bool $repeat
* @return void
*/
function smarty_block_image(array $params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
if (!$repeat) {
$content = $smarty->getTemplateVars('image') ? $content : '';
$smarty->assign('image', null);
return $content;
}
if (!array_key_exists('rendition', $params)) {
throw new \InvalidArgumentException("Rendition not set");
}
$renditions = Zend_Registry::get('container')->getService('image.rendition')->getRenditions();
if (!array_key_exists($params['rendition'], $renditions)) {
throw new \InvalidArgumentException("Unknown rendition");
}
$article = $smarty->getTemplateVars('gimme')->article;
if (!$article) {
throw new \RuntimeException("Not in article context.");
}
$articleRenditions = $article->getRenditions();
$articleRendition = $articleRenditions[$renditions[$params['rendition']]];
if ($articleRendition === null) {
$smarty->assign('image', false);
$repeat = false;
return;
}
if (array_key_exists('width', $params) && array_key_exists('height', $params)) {
$preview = $articleRendition->getRendition()->getPreview($params['width'], $params['height']);
$thumbnail = $preview->getThumbnail($articleRendition->getImage(), Zend_Registry::get('container')->getService('image'));
} else {
$thumbnail = $articleRendition->getRendition()->getThumbnail($articleRendition->getImage(), Zend_Registry::get('container')->getService('image'));
}
$smarty->assign('image', (object) array('src' => Zend_Registry::get('view')->url(array('src' => $thumbnail->src), 'image', true, false), 'width' => $thumbnail->width, 'height' => $thumbnail->height, 'caption' => $articleRendition->getImage()->getCaption(), 'photographer' => $articleRendition->getImage()->getPhotographer()));
}
示例2: smarty_function_liveCustomization
/**
* ...
*
* @param array $params
* @param Smarty $smarty
* @return string
*
* @package application.helper.smarty
* @author Integry Systems
*/
function smarty_function_liveCustomization($params, Smarty_Internal_Template $smarty)
{
$app = $smarty->getApplication();
if ($app->isCustomizationMode()) {
// theme dropdown
$themes = array_merge(array('barebone' => 'barebone'), array_diff($app->getRenderer()->getThemeList(), array('barebone')));
$smarty->assign('themes', $themes);
$smarty->assign('currentTheme', $app->getTheme());
if (!isset($params['action'])) {
include_once 'function.includeJs.php';
include_once 'function.includeCss.php';
smarty_function_includeJs(array('file' => "library/prototype/prototype.js"), $smarty);
smarty_function_includeJs(array('file' => "library/livecart.js"), $smarty);
smarty_function_includeJs(array('file' => "library/form/ActiveForm.js"), $smarty);
smarty_function_includeJs(array('file' => "library/form/Validator.js"), $smarty);
smarty_function_includeJs(array('file' => "backend/Backend.js"), $smarty);
smarty_function_includeJs(array('file' => "frontend/Customize.js"), $smarty);
smarty_function_includeCss(array('file' => "frontend/LiveCustomization.css"), $smarty);
} else {
$smarty->assign('mode', $app->getCustomizationModeType());
$smarty->assign('theme', $app->getTheme());
if ('menu' == $params['action']) {
return $smarty->fetch('customize/menu.tpl');
} else {
if ('lang' == $params['action']) {
return $smarty->fetch('customize/translate.tpl');
}
}
}
}
}
示例3: smarty_function_widget_template
/**
* Plugin for Smarty
*
* @param array $aParams
* @param Smarty_Internal_Template $oSmartyTemplate
*
* @return string|null
*/
function smarty_function_widget_template($aParams, $oSmartyTemplate)
{
if (!isset($aParams['name'])) {
trigger_error('Parameter "name" does not define in {widget ...} function', E_USER_WARNING);
return null;
}
$sWidgetName = $aParams['name'];
$aWidgetParams = isset($aParams['params']) ? $aParams['params'] : array();
$oEngine = Engine::getInstance();
// Проверяем делигирование
$sTemplate = E::ModulePlugin()->GetDelegate('template', $sWidgetName);
if ($sTemplate) {
if ($aWidgetParams) {
foreach ($aWidgetParams as $sKey => $sVal) {
$oSmartyTemplate->assign($sKey, $sVal);
}
if (!isset($aWidgetParams['params'])) {
/* LS-compatible */
$oSmartyTemplate->assign('params', $aWidgetParams);
}
$oSmartyTemplate->assign('aWidgetParams', $aWidgetParams);
}
$sResult = $oSmartyTemplate->fetch($sTemplate);
} else {
$sResult = null;
}
return $sResult;
}
示例4: smarty_function_backendLangMenu
/**
* Displays backend language selection menu
*
* @param array $params
* @param Smarty $smarty
* @return string
*
* @package application.helper.smarty
* @author Integry Systems
*/
function smarty_function_backendLangMenu($params, Smarty_Internal_Template $smarty)
{
if (!$smarty->getApplication()->getLanguageArray()) {
return false;
}
$smarty->assign('currentLang', Language::getInstanceByID($smarty->getApplication()->getLocaleCode())->toArray());
$smarty->assign('returnRoute', base64_encode($smarty->getApplication()->getRouter()->getRequestedRoute()));
return $smarty->display('block/backend/langMenu.tpl');
}
示例5: smarty_function_math
/**
* Smarty {math} function plugin
*
* Type: function<br>
* Name: math<br>
* Purpose: handle math computations in template
*
* @link http://www.smarty.net/manual/en/language.function.math.php {math}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
* @return string|null
*/
function smarty_function_math($params, $template)
{
static $_allowed_funcs = array('int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true, 'log' => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true, 'rand' => true, 'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => true);
// be sure equation parameter is present
if (empty($params['equation'])) {
trigger_error("math: missing equation parameter", E_USER_WARNING);
return;
}
$equation = $params['equation'];
// make sure parenthesis are balanced
if (substr_count($equation, "(") != substr_count($equation, ")")) {
trigger_error("math: unbalanced parenthesis", E_USER_WARNING);
return;
}
// match all vars in equation, make sure all are passed
preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]*)!", $equation, $match);
foreach ($match[1] as $curr_var) {
if ($curr_var && !isset($params[$curr_var]) && !isset($_allowed_funcs[$curr_var])) {
trigger_error("math: function call {$curr_var} not allowed", E_USER_WARNING);
return;
}
}
if (strpos($equation, '<<<') !== false) {
trigger_error("math: <<< not allowed", E_USER_WARNING);
return;
}
foreach ($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") {
// make sure value is not empty
if (strlen($val) == 0) {
trigger_error("math: parameter {$key} is empty", E_USER_WARNING);
return;
}
if (!is_numeric($val)) {
trigger_error("math: parameter {$key}: is not numeric", E_USER_WARNING);
return;
}
$equation = preg_replace("/\\b{$key}\\b/", " \$params['{$key}'] ", $equation);
}
}
$smarty_math_result = null;
eval("\$smarty_math_result = " . $equation . ";");
if (empty($params['format'])) {
if (empty($params['assign'])) {
return $smarty_math_result;
} else {
$template->assign($params['assign'], $smarty_math_result);
}
} else {
if (empty($params['assign'])) {
printf($params['format'], $smarty_math_result);
} else {
$template->assign($params['assign'], sprintf($params['format'], $smarty_math_result));
}
}
}
示例6: smarty_block_pageTitle
/**
* Set page title
*
* @package application.helper.smarty
* @author Integry Systems
*/
function smarty_block_pageTitle($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
if (!$repeat) {
$smarty->assign('TITLE', strip_tags($content));
if (isset($params['help'])) {
$content .= '<script type="text/javascript">Backend.setHelpContext("' . $params['help'] . '")</script>';
}
$GLOBALS['PAGE_TITLE'] = $content;
$smarty->assign('PAGE_TITLE', $content);
$smarty->setGlobal('PAGE_TITLE', $content);
}
}
示例7: smarty_function_partition
/**
* This function partitions an array into n subarrays which can be used for column layouts.
*
* @example tests/test.tpl
*
* @license MIT
*
* @see http://www.php.net/array_chunk#75022 source of the original function
*
* @param array $params An array consisting of the keys array, size, and name; name is the name of the output array, size is the number of columns, array is the array to be partitioned
* @param Smarty_Internal_Template $template Used by Smarty internally
*
* @return array Returns the partitoned array
*/
function smarty_function_partition($params, Smarty_Internal_Template $template = null)
{
// First check whether all parameters are present.
$requiredParamters = ['size', 'name', 'array'];
$nonEmptyParameters = ['size', 'name'];
foreach ($requiredParamters as $parameterToCheck) {
if (!array_key_exists($parameterToCheck, $params)) {
return false;
}
}
foreach ($nonEmptyParameters as $parameterToCheck) {
// Not using empty() since that would cause problems with 0-values.
if (!isset($params[$parameterToCheck])) {
return false;
}
}
// Then, we inline the parameters into better understandable variables.
$numberOfParts = $params['size'];
$inputList = $params['array'];
$outputName = $params['name'];
// If the number of parts requested is non-positive, error out.
if ((int) $numberOfParts <= 0 || !is_array($inputList)) {
if ($template) {
$template->assign($outputName, []);
return;
} else {
return [$outputName => []];
}
}
// Set up the loop to split the input up.
$lengthOfList = count($inputList);
$lengthOfOnePart = floor($lengthOfList / $numberOfParts);
$lengthOfRemainder = $lengthOfList % $numberOfParts;
$partition = [];
$mark = 0;
// Loop over the array and fill the columns.
// The first column may contain up to (n -1) more elements than the other columns.
// n is equal to the number of parts.
for ($px = 0; $px < $numberOfParts; $px++) {
$increment = $px < $lengthOfRemainder ? $lengthOfOnePart + 1 : $lengthOfOnePart;
$partition[$px] = array_slice($inputList ?: [], $mark, $increment);
$mark += $increment;
}
// Return the partitioned array with the pre-defined name.
if ($template) {
$template->assign($outputName, $partition);
} else {
return [$outputName => $partition];
}
}
示例8: smarty_block_tip
/**
* Display a tip block
*
* @package application.helper.smarty
* @author Integry Systems
*
* @package application.helper.smarty
*/
function smarty_block_tip($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
if (!$repeat) {
$smarty->assign('tipContent', $content);
return $smarty->display('block/backend/tip.tpl');
}
}
示例9: smarty_block_fis_widget
function smarty_block_fis_widget($params, $content, Smarty_Internal_Template $template, &$repeat)
{
if (!$repeat) {
if (isset($params['extends'])) {
$path = $params['extends'];
unset($params['extends']);
foreach ($params as $key => $v) {
if ($template->getTemplateVars($key)) {
$params[$key] = $template->getTemplateVars($key);
}
}
return $content = $template->getSubTemplate($path, $template->cache_id, $template->compile_id, null, null, $params, Smarty::SCOPE_LOCAL);
} else {
return $content;
}
} else {
if (isset($params['extends'])) {
unset($params['extends']);
}
foreach ($params as $key => $v) {
$value = $template->getTemplateVars($key);
if ($value === null) {
$template->assign($key, $v, true);
}
}
}
}
示例10: smarty_block_begin_widget
/**
* Allows to use Yii beginWidget() and endWidget() methods in a simple way.
* There is a variable inside a block wich has 'widget' name and represent widget object
*
* Example:
* {begin_widget name="activeForm" foo="" bar="" otherParam="" [...]}
* {$widget->some_method_or_variable}
* {/begin_widget}
*
* @param array $params parameters
* @param string $content contents of the block
* @param Smarty_Internal_Template $template template object
* @param boolean &$repeat repeat flag
* @return string
* @author t.yacenko (thekip)
*/
function smarty_block_begin_widget($params, $content, $template, &$repeat)
{
$controller_object = $template->tpl_vars['this']->value;
if ($controller_object == null) {
throw new CException("Can't get controller object from template. Error.");
}
if ($repeat) {
//tag opened
if (!isset($params['name'])) {
throw new CException("Name parameter should be specified.");
}
$widgetName = $params['name'];
unset($params['name']);
//some widgets has 'name' as property. You can pass it by '_name' parameter
if (isset($params['_name'])) {
$params['name'] = $params['_name'];
unset($params['_name']);
}
$template->assign('widget', $controller_object->beginWidget($widgetName, $params, false));
} else {
//tag closed
echo $content;
$controller_object->endWidget();
$template->clearAssign('widget');
}
}
示例11: smarty_function_activeGrid
/**
* Displays ActiveGrid table
*
* @param array $params
* @param Smarty $smarty
* @return string
*
* @package application.helper.smarty
* @author Integry Systems
*/
function smarty_function_activeGrid($params, Smarty_Internal_Template $smarty)
{
if (!isset($params['rowCount']) || !$params['rowCount']) {
$params['rowCount'] = 15;
}
foreach ($params as $key => $value) {
$smarty->assign($key, $value);
}
if (isset($params['filters']) && is_array($params['filters'])) {
$smarty->assign('filters', $params['filters']);
}
$smarty->assign('url', $smarty->getApplication()->getRouter()->createUrl(array('controller' => $params['controller'], 'action' => $params['action']), true));
$smarty->assign('thisMonth', date('m'));
$smarty->assign('lastMonth', date('Y-m', strtotime(date('m') . '/15 -1 month')));
return $smarty->display('block/activeGrid/gridTable.tpl');
}
示例12: smarty_function_generate_id
/**
* 生成当前请求唯一的ID,并赋值给制定的模板变量名,依赖与全局模板变量__unique__
* 当__unique__存在的时候,生成的ID值会自动缀上这个数值,用于生成不同请求间的唯一ID
* 一般用于页面整体内容作为ajax响应结果写入页面,而这个页面又需要引入有ID的widget这种情况
* @param String $params.assign 生成的参数赋值给的模板变量名,默认赋值给WIDGET_ID
* @param Smarty_Internal_Template $template
*/
function smarty_function_generate_id($params, Smarty_Internal_Template $template)
{
$assign = !empty($params['assign']) ? $params['assign'] : "WIDGET_ID";
static $id = 0;
$id++;
$template->assign($assign, $id . $template->tpl_vars["__unique__"]);
}
示例13: smarty_function_getdatatablerow
/**
* PixelManager CMS (Community Edition)
* Copyright (C) 2016 PixelProduction (http://www.pixelproduction.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function smarty_function_getdatatablerow($params, Smarty_Internal_Template $template)
{
if (!isset($params['class']) || !isset($params['var']) || !isset($params['row'])) {
return;
}
if (isset($params['page'])) {
$page_id = $params['page'];
} else {
$page_id = $template->getTemplateVars('pageId');
}
if (isset($params['language'])) {
$language_id = $params['language'];
} else {
$language_id = $template->getTemplateVars('languageId');
if ($language_id === null) {
$language_id = Config::get()->languages->standard;
}
}
$data = array();
if (isset($params['row'])) {
$data_table = new $params['class']();
$data = $data_table->getRowForFrontend($params['row'], $page_id, $language_id);
}
if (isset($params['var'])) {
$template->assign($params['var'], $data);
}
}
示例14: theliaModule
/**
* Process theliaModule template inclusion function
*
* This function accepts two parameters:
*
* - location : this is the location in the admin template. Example: folder-edit'. The function will search for
* AdminIncludes/<location>.html file, and fetch it as a Smarty template.
* - countvar : this is the name of a template variable where the number of found modules includes will be assigned.
*
* @param array $params
* @param \Smarty_Internal_Template $template
* @internal param \Thelia\Core\Template\Smarty\Plugins\unknown $smarty
*
* @return string
*/
public function theliaModule($params, \Smarty_Internal_Template $template)
{
$content = null;
$count = 0;
if (false !== ($location = $this->getParam($params, 'location', false))) {
if ($this->debug === true && $this->request->get('SHOW_INCLUDE')) {
echo sprintf('<div style="background-color: #C82D26; color: #fff; border-color: #000000; border: solid;">%s</div>', $location);
}
$moduleLimit = $this->getParam($params, 'module', null);
$modules = ModuleQuery::getActivated();
/** @var \Thelia\Model\Module $module */
foreach ($modules as $module) {
if (null !== $moduleLimit && $moduleLimit != $module->getCode()) {
continue;
}
$file = $module->getAbsoluteAdminIncludesPath() . DS . $location . '.html';
if (file_exists($file)) {
$output = trim(file_get_contents($file));
if (!empty($output)) {
$content .= $output;
$count++;
}
}
}
}
if (false !== ($countvarname = $this->getParam($params, 'countvar', false))) {
$template->assign($countvarname, $count);
}
if (!empty($content)) {
return $template->fetch(sprintf("string:%s", $content));
}
return "";
}
示例15: smarty_block_image
/**
* Image block
*
* @param array $params
* @param string $content
* @param Smarty_Internal_Template $smarty
* @param bool $repeat
* @return void
*/
function smarty_block_image(array $params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
if (!$repeat) {
$content = $smarty->getTemplateVars('image') ? $content : '';
$smarty->assign('image', null);
return $content;
}
if (!array_key_exists('rendition', $params)) {
throw new \InvalidArgumentException("Rendition not set");
}
$cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
$renditionService = \Zend_Registry::get('container')->getService('image.rendition');
$cacheKey = $cacheService->getCacheKey(array('theme_renditions'), 'theme');
if ($cacheService->contains($cacheKey)) {
$renditions = $cacheService->fetch($cacheKey);
} else {
$renditions = $renditionService->getRenditions();
$cacheService->save($cacheKey, $renditions);
}
if (!array_key_exists($params['rendition'], $renditions)) {
throw new \InvalidArgumentException("Unknown rendition");
}
$article = $smarty->getTemplateVars('gimme')->article;
if (!$article) {
throw new \RuntimeException("Not in article context.");
}
$articleRenditions = $article->getRenditions();
$articleRendition = $articleRenditions[$renditions[$params['rendition']]];
if ($articleRendition === null) {
$smarty->assign('image', false);
$repeat = false;
return;
}
$image = null;
if (array_key_exists('width', $params) && array_key_exists('height', $params)) {
$image = $renditionService->getArticleRenditionImage($article->number, $params['rendition'], $params['width'], $params['height']);
} else {
$image = $renditionService->getArticleRenditionImage($article->number, $params['rendition']);
}
$imageService = \Zend_Registry::get('container')->getService('image');
$preferencesService = \Zend_Registry::get('container')->getService('preferences');
$caption = $imageService->getCaption($articleRendition->getImage(), $article->number, $article->language->number);
if ($preferencesService->get('MediaRichTextCaptions', 'N') == 'N') {
$caption = MetaDbObject::htmlFilter($caption);
}
$smarty->assign('image', (object) array('src' => \Zend_Registry::get('view')->url(array('src' => $image['src']), 'image', true, false), 'width' => $image['width'], 'height' => $image['height'], 'caption' => $caption, 'description' => $articleRendition->getImage()->getDescription(), 'photographer' => $articleRendition->getImage()->getPhotographer(), 'original' => $image['original']));
}