Please note: As of Friday, May 3, 2013, cpshop is officially retired, and is no longer for sale. detailsusing cpshop hooks
Hooks are a powerful tool in the quest to customize your cpshop pages further based on the page type, and a new addition to cpshop 2.3.
Hooks are somewhat like the idea of server side includes (SSI). Hooks allow you to define locations in the page where you want a block of content to appear, by marking those locations with a <[hook:hookname]> tag, where "hookname" would be replaced with the hook's name (duh). The great thing about hooks is that you can decide when the hooks show up as well, meaning you can create content that appears, say, only on pages with mousepads, or only on pages with products from a certain store.
when to use hooks
Here are a few examples of when you might use hooks.
Problem: I want to have a special message appear on any poster product pages.
Solution: Use product type hooks for all three poster product types: small poster, large poster and mini poster (product types 53, 54 and 92, respectively).
Problem: I want to put a disclaimer above a particular store's products.
Solution: Use a store ID hook.
Problem: I want a piece of HTML to appear in every page of my cpshop, except for the pages under a particular alias.
Solution: Create an alias hook and an all-pages hook, both with the same hook name. Put your special HTML in the all-pages hook content file, and leave the alias hook content file blank.
an example hook
It might be a little easier if we go through an example of creating a hook.
Let's say you have a special product you'd like to feature; in this example, let's assume it's this Junior Ringer T-Shirt. At the top of the product page, you'd like to place a "Product Of The Month" banner.
If this was your first hook, then you'd first add a "cphooks" subdirectory to your cpshop installation. All hook content goes in that directory.
Then you'd update your store template, adding a new hook called, appropriately enough, "banner." You'd place a <[hook:banner]> tag in your cpshop template where you'd want the banner to appear.
The next step is to create the actual hook content file, which is basically just a text file with HTML in it. Hooks can be used to target a specific alias, product type, store ID, section, or product, and the file name determines how the hook is targeted. The general file naming convention of a hook content file is:
[cpshop file].[target type].[target criteria].[hook name].txt
In this case, you'd want to create a hook for product no. 16826273. So you'd create the HTML to display your "Product Of The Month" graphic, and then save it in a file named:
which you'd then upload into the cphooks directory.
Finally, you'd go to cpadmin's Other Display Options section, and set the "Process Hooks?" option to "process hooks in template and code."
That's it. Now whenever that product page loaded, cpshop would see the hook content file, and display its contents where the <[hook:banner]> tag appeared in your template. On other pages, the hook wouldn't show anything -- it would just disappear.
hook target types & hierarchy
cpshop will look for hooks in the following order, using the first one it finds.
* pages within a section (subsections and product pages) will also qualify
||filename format & example
||cpshop.cgi.type.[product type no].[hookname].txt
||all product pages
||store ID alias
Because hooks are such an advanced feature, it's often much harder to implement than most cpshop features. So if you're having trouble getting hooks to work, here are several things that you should double- and triple-check.