Jump to content

[SOLVED] is it possible to create a new hook through a module ?


jemmeli
 Share

Recommended Posts

hello everybody

 

is it possible to create a new hook trou a module , the new hook will affected automatically to a file tpl i choose for example the file shopping-cart-product-line.tpl without interaction from the user i mean the user dont need to enter the tpl file and whrite the folowing code:

 

{hook h='myNewCoolHook'}

 

instead this code will be added automatically in a Dom element of the shopping-cart-product-line.tpl

 

this is a challenge for me i did some research I found that I must add a function to the module for the new hook like this:

 

Public function hookmyNewCoolHook($params){
 return somthing;
}

 

and also add the hook in the install function to the module in order to install it

 

but when it comes to the tpl file i found that this can not be automatically it need some interaction by the user to whrite as mentioned above :

{hook h='myNewCoolHook'}

 

i want to do it all automatically by the module

 

and thank you for the help in advance

Edited by jemmeli (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

You can't add a hook and just expect the output of the hook to magically appear in output of shopping-cart-product-line.tpl.

 

Since shopping-cart-product-line.tpl does not have any existing hooks, then there is really nothing you can do with this theme file unless you override or alter the file itself, which you say you want to avoid.

 

The next thing I would look to do is use shopping-cart.tpl. This has 2 existing hooks (HOOK_SHOPPING_CART and HOOK_SHOPPING_CART_EXTRA). What you could do is have your module register one of these hooks, and dump your output into a hidden div element. Then using javascript/jquery, you can then move the content of this div wherever you want it to appear.

  • Like 1

Share this post


Link to post
Share on other sites

thank you a lot "bellini13" for you answer .

 

i understand most of your ansewer , but the part related to the dumping an output into a hidden element i did not understood well please if you can give me a go with a sipme code , or if there is a reference on the web talking about this methode

 

and thank you in advance

Share this post


Link to post
Share on other sites

it is solved "bellini13":

 

I used the hook hookdisplayShoopingCart like this:

 

public function hookdisplayShoppingCartFooter($params) {

global $smarty;


}

//(this is the inforrmaion that I want dump it to hidden div)--------------------------------------------------------------------------------
$sql = 'SELECT * FROM '._DB_PREFIX_.'cus ORDER BY id_cus DESC LIMIT 1';
if ($results = Db::getInstance()->ExecuteS($sql))
foreach ($results as $row){
$info_cus = 'ID du produit =>'.$row['id_product'].' :<br> TEXT =>'.$row['value_text'].' :<br> position TEXT =>'.$row['position_text'].
' :<br> FOTO =>'.$row['value_foto'].' :<br> Position du FOTO =>'.$row['position_foto'].' :<br> Le prix =>'.$row['new_price'];
}
//---------------------------------------------------------------------------------------------------------------------------------------------------


$this->context->smarty->assign(array(
'total_price' => $new_price,
'cus' => $info_cus//the duping variable--------------------------------------------------------------------------------------------------------
));
return $this->display(__FILE__, 'xxx.tpl');

 }

 

and then in my tpl file called xxx.tpl i put this code and a little jquery to hide the div :D

 

<div id="hidden_div">{$cus}</div>

<script type="text/javascript">

alert("hhhhh");
       //$("#hidden_div").hide();

</script>

 

and it WOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOORKS fine

Share this post


Link to post
Share on other sites

  • 4 weeks later...

Hi Bellini13,

 

I have a similar problem, i am trying to add a new hook to category.tpl wihout the need for editing.

 

I am trying to create a breadcrumb module with BO configuration, this would need to add it's own hook in to all the relevant TPL files which currently display the breadcrumb by an include.

{include file="$tpl_dir./breadcrumb.tpl"}

Is this possible??

 

Regards

 

You can't add a hook and just expect the output of the hook to magically appear in output of shopping-cart-product-line.tpl.

Since shopping-cart-product-line.tpl does not have any existing hooks, then there is really nothing you can do with this theme file unless you override or alter the file itself, which you say you want to avoid.

The next thing I would look to do is use shopping-cart.tpl. This has 2 existing hooks (HOOK_SHOPPING_CART and HOOK_SHOPPING_CART_EXTRA). What you could do is have your module register one of these hooks, and dump your output into a hidden div element. Then using javascript/jquery, you can then move the content of this div wherever you want it to appear.

Share this post


Link to post
Share on other sites

There are no existing hooks for the breadcrumb.tpl file.  So you would have to create your own hook, and then alter the theme file and the frontcontroller if you expect your output to be included

 

Now you might be able to use the "top of pages" hook to add your custom breadcrumb, but you still would have to edit the existing breadcrumb file if you do not want that to appear

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
 Share

×
×
  • Create New...

Important Information

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