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:
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!!!