Teapot Creative Posted August 28, 2014 Share Posted August 28, 2014 (edited) HI I am creating a custom module and need to pass the product name to a form value within the template file. What code do I need in my .tpl and module .php file to achieve this? Thanks in advance Nick Edited August 28, 2014 by Teapot Creative (see edit history) Link to comment Share on other sites More sharing options...
PhpMadman Posted August 28, 2014 Share Posted August 28, 2014 (edited) $product = new Product($id_product, false, $id_lang) $product->name and then assign it in smarty. Edited August 28, 2014 by PhpMadman (see edit history) Link to comment Share on other sites More sharing options...
Teapot Creative Posted August 28, 2014 Author Share Posted August 28, 2014 Hi Sorry being really thick... "and then assign it in smarty".? where to an how do you assign it in smarty? Kind regards Nick Link to comment Share on other sites More sharing options...
Eolia Posted August 28, 2014 Share Posted August 28, 2014 In your php file: $this->context->smarty->assign(array( 'languages' => $languages, 'my_variable' => $some_variable )); return $this->display(__file__, 'views/template/front/my_view.tpl'); and in my_view.tpl: {capture name=path}{l s='Test'}{/capture} {include file="$tpl_dir./breadcrumb.tpl"} <h2>{l s='My Title' mod='mymodule'}</h2> {if !empty($my_variable)} <p>{l s='This is my variable' mod='mymodule'} : {$my_variable}</p> {/if} Link to comment Share on other sites More sharing options...
Teapot Creative Posted August 28, 2014 Author Share Posted August 28, 2014 Hi Is it put within the "public function __construct()" in the .php file? Nick Link to comment Share on other sites More sharing options...
Eolia Posted August 28, 2014 Share Posted August 28, 2014 Oh no ! Look at this archive please: https://github.com/PrestaEdit/Canvas-Module-Prestashop-15 and this: http://doc.prestashop.com/display/PS16/Creating+a+PrestaShop+Module Link to comment Share on other sites More sharing options...
Teapot Creative Posted August 28, 2014 Author Share Posted August 28, 2014 Hi Is this assigned correctly? public function hookdisplayLeftColumnProduct($params) { $this->context->smarty->assign(array($product = new Product($id_product, false, $id_lang), $product->name, )); return $this->display(__FILE__, 'my_tpl.tpl'); } Link to comment Share on other sites More sharing options...
Eolia Posted August 28, 2014 Share Posted August 28, 2014 (edited) No... public function hookdisplayLeftColumnProduct($params) { $id_product = Tools::getValue('id_product'); $product = new Product($id_product, false, $id_lang); $this->context->smarty->assign(array( 'name' => $product->name, )); return $this->display(__FILE__, 'my_tpl.tpl'); } and in your my_tpl.tpl use the {$name} variable Edited August 28, 2014 by Eolia (see edit history) Link to comment Share on other sites More sharing options...
Teapot Creative Posted August 28, 2014 Author Share Posted August 28, 2014 (edited) Thanks for that... I have added the code but just get the word "Array" in the front end where I have used variable {$name} Thanks again for your help.. looks like its almost there.. Any ideas why its just resulting in the word Array instead of the product title? Nick Edited August 28, 2014 by Teapot Creative (see edit history) Link to comment Share on other sites More sharing options...
Eolia Posted August 28, 2014 Share Posted August 28, 2014 Thanks for that... I have added the code but just get the word "Array" in the front end where I have used {$name} Thanks again for your help.. looks like its almost there.. Nick Yes, because you load each name in all languages ... if you want to display only the product name in the current language, use: $this->context = Context::getContext(); $product = new Product($id_product, false,$this->context->language->id); Link to comment Share on other sites More sharing options...
Teapot Creative Posted August 28, 2014 Author Share Posted August 28, 2014 Hi FANTASTIC! many thanks Eolia .... works a treat. Members like you make this forum great... thanks for your quick replies Nick Link to comment Share on other sites More sharing options...
Eolia Posted August 28, 2014 Share Posted August 28, 2014 Remember to mark this post as "solved" (edit the first post and modify the title) 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