Jump to content

One hook multiple .tpl files (custom tabs)


Recommended Posts

Posted (edited)

Hello,

i'm working on module (prestashop 1.7) that creates custom tabs on product page. I have a hook, lets call it displayNewTabs and i would like to assign to it multiple, different .tpl files so it can display on seperate tabs different info without the need of making a new hook.

Ideally it would look something like:

hookDisplayNewTabs($params){
	$array_contact = delivery_info();
	$this->context->smarty->assign($array_contact);
	return $this->display(__FILE__, 'newtabs_contact.tpl');
}

hookDisplayNewTabs1($params){
	$array_other_products = linkproducts();
	$this->context->smarty->assign($array_other_products);
	return $this->display(__FILE__, 'newtabs_other_products.tpl');
}

hookDisplayNewTabs2($params){
	(...)
	return $this->display(__FILE__, 'newtabs2.tpl');
}
hookDisplayNewTabs3($params){
	(...)
	return $this->display(__FILE__, 'newtabs3.tpl');
}

 

Is it possible to do it in such way or should i try a different aproach?

 

EDIT:

OK, i think i've solved it by doing a one .tpl file that will include other .tpl files and pass them an array with required variables. At least I think that it will work.

Edited by Bugas (see edit history)

Share this post


Link to post
Share on other sites

I would create 1 hook and pass the tab number as a parameter, allowing you something like:

hookDisplayNewTabs($params){
	
	switch($params['tab_number']) {
		case '':
			$array_contact = delivery_info();
			$this->context->smarty->assign($array_contact);
			$html =  $this->display(__FILE__, 'newtabs_contact.tpl');
			break;
		case '1':
			$array_other_products = linkproducts();
			$this->context->smarty->assign($array_other_products);
			$html = $this->display(__FILE__, 'newtabs_other_products.tpl');
			break;
		case '2':
			...
			break;
		default:
			$html = 'Some default response';
			break;
	}
	return $html;
}

 

Share this post


Link to post
Share on other sites

Not exactly what i'm trying to achieve as i need those tabs to be displayed at once. But one .tpl file with multiple .tpl in it is the right way to go... i think ;)

Thank You for Your help and time.

Best regards

 

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More