Jump to content

[SOLVED] Pass product name to a custom template file?


Teapot Creative

Recommended Posts

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

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 by Eolia (see edit history)
Link to comment
Share on other sites

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 by Teapot Creative (see edit history)
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...