dongnao2582 2017-06-19 08:02
浏览 58

Shopware 5.2.24上的插件中的模板继承不起作用

I try the example program "Slogan of the day" on shopware 5.2.24

But the code doesn't work.

In the file Bootstrap.php, I defined the 3 important functions. In the function install, the callback function "onFrontendPostDispatch" will be called.

public function install()
{
    $this->subscribeEvent(
        'Enlight_Controller_Action_PostDispatchSecure_Frontend',
        'onFrontendPostDispatch'
    );

    $this->createConfig();

    return true;
}

private function createConfig()
{
    $this->Form()->setElement(
        'select',
        'font-size',
        array(
            'label' => 'Font size',
            'store' => array(
                array(12, '12px'),
                array(18, '18px'),
                array(25, '25px')
            ),
            'value' => 12
        )
    );

    $this->Form()->setElement('boolean', 'italic', array(
        'value' => true,
        'label' => 'Italic'
    ));
}

In this callback function, I definded the parameters for the new tpl file and the location of the new tpl file: [ _ DIR _ . '/Views' ]

public function onFrontendPostDispatch(Enlight_Event_EventArgs $args)
{
    /** @var \Enlight_Controller_Action $controller */
    $controller = $args->get('subject');
    $view = $controller->View();

    $view->addTemplateDir(
        __DIR__ . '/Views'
    );

    $view->assign('sloganSize', $this->Config()->get('font-size'));
    $view->assign('italic', $this->Config()->get('italic'));
    $view->assign('slogan', $this->getSlogan());

}

public function getSlogan()
{
    return array_rand(
        array_flip(
            array(
                'My Slogan Number 1',
                'My Slogan Number 2',
                'My Slogan Number 3',
            )
        )
    );
}

The new tpl file is:

{extends file="parent:frontend/index/index.tpl"}

{block name="frontend_index_navigation_categories_top_include"}

<style>
    .slogan-box {
        width:100%;
        text-align:center;
    }
    .slogan {
        {if $italic}font-style:italic;{/if}
        font-size:{$sloganSize}px;
    }
</style>

<div class="slogan-box">
    <span class="slogan">{$slogan}</span>
</div>

{$smarty.block.parent}

{/block}

The location of new tpl file is:

enter image description here

But in the Homepage, I can't see the slogan... It doesn't work.

The file Bootstrap.php works fine. But the slogan can't be seen on the homepage.

Is the connection between the Bootstrap.php und index.tpl wrong?

Does anyone know where i have gone wrong? Thans a lot!!!

  • 写回答

2条回答 默认 最新

  • drxd54816 2017-06-20 05:36
    关注

    It seems, createConfig function is undefined. Either define the function or comment out function call $this->createConfig(); inside install() function.
    Now re-install your plugin from backend Plugin Manager. It should work.

    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图