THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline

#1 problem with plugin smarty

(05-11-2014 11:55:21)


Hello i've problem with smarty plugin.

<?php
/*************************************************************************************/
/*      This file is part of the Thelia package.                                     */
/*                                                                                   */
/*      Copyright (c) OpenStudio                                                     */
/*      email : dev@thelia.net                                                       */
/*      web : http://www.thelia.net                                                  */
/*                                                                                   */
/*      For the full copyright and license information, please view the LICENSE.txt  */
/*      file that was distributed with this source code.                             */
/*************************************************************************************/

namespace Search\Smarty\Plugins;

use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;


/**
 * Class Search
 * @package Search\Smarty\Plugins
 */
class Search extends AbstractSmartyPlugin
{
    /** @var \Thelia\Core\HttpFoundation\Request The Request */
    protected $request;

    /** @var ContainerInterface Service Container */
    protected $container = null;
    /**
     * @param ContainerInterface $container
     */
    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;

        $this->request = $container->get('request');
    }

    /**
     * Get postage amount for cart
     *
     * @param array                     $params   Block parameters
     * @param mixed                     $content  Block content
     * @param \Smarty_Internal_Template $template Template
     * @param bool                      $repeat   Control how many times
     *                                            the block is displayed
     *
     * @return mixed
     */
    public function searchForm($params, $content, \Smarty_Internal_Template $template, &$repeat)
    {
        if (! $repeat) {
            return null;
        }        
        $template->assign('test', 'blablabla');
    }

    /**
     * Defines the various smarty plugins handled by this class
     *
     * @return SmartyPluginDescriptor[] smarty plugin descriptors
     */
    public function getPluginDescriptors()
    {
        return array(
            new SmartyPluginDescriptor('block', 'search_form_block', $this, 'searchForm')
        );
    }
}

now in template I'm using:

{search_form_block}
{$test}
{/search_form_block}

but variable $test didnt work, why ?

Last edited by michal84 (05-11-2014 11:56:25)