переписать плагин в синтаксисе 3 - PullRequest
0 голосов
/ 27 марта 2012

Мне нужно переписать, как называется модификатор 'truncate', потому что это вызывает ошибку. _getfilepath не существует в версии 3

$this->_engine = new Smarty();
$this->_engine->template_dir = $config->paths->templates;
$this->_engine->compile_dir = sprintf('%s/tmp/templates_c',
                                      $config->paths->data);

 $this->_engine->plugins_dir = array($config->paths->base .
                           '/woonbel/include/Templater/plugins','plugins');



function smarty_function_breadcrumbs($params, $smarty)
{
    $defaultParams = array('trail'     => array(),
                           'separator' => ' > ',
                           'truncate'  => 40);

    // initialize the parameters
    foreach ($defaultParams as $k => $v) {
        if (!isset($params[$k]))
            $params[$k] = $v;
    }

    // load the truncate modifier
    if ($params['truncate'] > 0)

require_once $ smarty-> getPluginsDir ('modifier', 'truncate');

 $links = array();
        $numSteps = count($params['trail']);
        for ($i = 0; $i < $numSteps; $i++) {
            $step = $params['trail'][$i];

            // truncate the title if required
            if ($params['truncate'] > 0)
                $step['title'] = smarty_modifier_truncate($step['title'],
                                                          $params['truncate']);

            // build the link if it's set and isn't the last step
            if (strlen($step['link']) > 0 && $i < $numSteps - 1) {
                $links[] = sprintf('<a href="%s" title="%s">%s</a>',
                                   htmlSpecialChars($step['link']),
                                   htmlSpecialChars($step['title']),
                                   htmlSpecialChars($step['title']));
            }
            else {
                // either the link isn't set, or it's the last step
                $links[] = htmlSpecialChars($step['title']);
            }
        }

        // join the links using the specified separator
        return join($params['separator'], $links);
    }

1 Ответ

2 голосов
/ 27 марта 2012

вы ищете (не задокументировано публично) функцию loadPlugin ():

$smarty->loadPlugin('smarty_modifier_truncate', true);
$string = smarty_modifier_truncate($string);

Обновить тестовый набор:

<?php
error_reporting(E_ALL);
require_once 'path-to/Smarty.class.php';

$smarty = new Smarty();
$smarty->loadPlugin('smarty_modifier_truncate', true);
$string = 'hello world I should be truncated to some smaller string';
$string = smarty_modifier_truncate($string, 10);
var_dump($string);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...