mcluca Posted January 6, 2013 Share Posted January 6, 2013 Hi i use ps 1.4 and i want use a light php script for banner rotation like this: <?php $advert = array(); $advert[] = '<a href="#">Banner 1</a>'; $advert[] = '<a href="#">Banner 2</a>'; $advert[] = '<a href="#">Banner 3</a>'; shuffle($advert); echo $advert[0]; ?> in index.tpl but i don't understand how do it because {php} or {include} not work in ps 1.4 version I read to create smarty variable use assign function but HOW? Thanks Link to comment Share on other sites More sharing options...
vekia Posted January 7, 2013 Share Posted January 7, 2013 in prestashop based on version 1.4 you can use php code in {php} {/php} tags. in prestashop 1.5+ it isn't possible Link to comment Share on other sites More sharing options...
Raphaël Malié Posted January 7, 2013 Share Posted January 7, 2013 Hello, the best way to do that : 1. Create a file /override/classes/FrontController.php with this code : <?php class FrontController extends FrontControllerCore { public function init() { parent::init(); $advert = array(); $advert[] = '<a href="#">Banner 1</a>'; $advert[] = '<a href="#">Banner 2</a>'; $advert[] = '<a href="#">Banner 3</a>'; shuffle($advert); self::$smarty->assign('my_adverts', $adverts); } } 2. In your .tpl template file you can now use {$my_adverts} Regards Link to comment Share on other sites More sharing options...
vekia Posted January 7, 2013 Share Posted January 7, 2013 Raphaël Malié got right, in this case is the best way to use php code. As the extension name of file the says (.tpl) it's a template file - not controller ! Link to comment Share on other sites More sharing options...
mcluca Posted January 7, 2013 Author Share Posted January 7, 2013 Thank for information PrestArchitecte but when insert {$my_adverts} in index.tpl under {$HOOK_HOME} or in header.tpl under <div id="center_column"> also inside a <div> tag nothing appear. Why? I created frontcontroller.php with your code inside /override/class/ Thank Link to comment Share on other sites More sharing options...
Raphaël Malié Posted January 7, 2013 Share Posted January 7, 2013 In order to be sure that this class is correctly called, please add this code : die('test'); after self::$smarty->assign('my_adverts', $adverts); Do you see a blank page with "test" when you refresh your page in your browser ? Link to comment Share on other sites More sharing options...
mcluca Posted January 7, 2013 Author Share Posted January 7, 2013 Yes i see blank page with test. I have put {$my_adverts} in index.tpl but also i don't see the banner in page code. Where is the problem? thank Link to comment Share on other sites More sharing options...
Raphaël Malié Posted January 7, 2013 Share Posted January 7, 2013 Ok replace the overriden FrontController file by this content : <?php class FrontController extends FrontControllerCore { public function displayContent() { parent::init(); $advert = array(); $advert[] = '<a href="#">Banner 1</a>'; $advert[] = '<a href="#">Banner 2</a>'; $advert[] = '<a href="#">Banner 3</a>'; shuffle($advert); self::$smarty->assign('my_adverts', $adverts); parent::displayContent(); } } Does this work ? Link to comment Share on other sites More sharing options...
mcluca Posted January 7, 2013 Author Share Posted January 7, 2013 No nothing. Link to comment Share on other sites More sharing options...
Raphaël Malié Posted January 7, 2013 Share Posted January 7, 2013 Oh, I see why, i used $adverts (with a S) in the assign method Just fix the var name Link to comment Share on other sites More sharing options...
mcluca Posted January 7, 2013 Author Share Posted January 7, 2013 (edited) ok now i can call variable but in page see array where i insert {$my_adverts} Any solution? Edited January 7, 2013 by mcluca (see edit history) Link to comment Share on other sites More sharing options...
Raphaël Malié Posted January 7, 2013 Share Posted January 7, 2013 Yes, you should do that : <?php class FrontController extends FrontControllerCore { public function displayContent() { parent::init(); $advert = array(); $advert[] = '<a href="#">Banner 1</a>'; $advert[] = '<a href="#">Banner 2</a>'; $advert[] = '<a href="#">Banner 3</a>'; self::$smarty->assign('my_adverts', $advert[array_rand($advert)]); parent::displayContent(); } } Link to comment Share on other sites More sharing options...
Vilas Posted January 11, 2013 Share Posted January 11, 2013 Will be great if anyone help me to resolve below topic. www.prestashop.com/forums/topic/214319-pop-up-to-capture-visitor-email/ Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now