Can I get blockbanner to open a picture in fancybox on every page?



  • I’m already using fancybox to display pictures in a CMS gallery page, which I accomplished by putting this javascript into ‘Custom Code’ in the back office:

    $(document).ready(function() { $("a.fancybox").fancybox(); });
    

    So for the banner link I thought, ‘Great, I probably just need to edit blockbanner.tpl to append class="fancybox" to the URL.’ But nothing is ever that straightforward, is it? It actually works on CMS and product pages, but not on the home, category or search pages. I’ve tried putting that js directly into the global.js file and the index.js file but it doesn’t work. Any ideas what, if anything, I can do to fix this?



  • Investigating further I remembered I’d also had to insert these two lines…

    $this->addCSS(_PS_CSS_DIR_.'jquery.fancybox-1.3.4.css', 'screen');
    $this->addJqueryPlugin('fancybox');
    

    …at the bottom of the setMedia function in CMSController.php so I guess that’s why it’s working on CMS pages. Is there somewhere I could put this code – or something similar – so that fancybox will work wherever it’s called from?



  • Okay, so I’ve figured out I can add those two lines of code to each individual controller and that gets me what I want, but it seems like an awfully laborious way of doing it. Is there somewhere I can add them globally so it’s just one file to edit?



  • There is no file CMSController.php. Probably you mean CmsController.php.

    If you want to have this in all controllers, add the code to the parent of this controller, classes/controller/FrontController.php.



  • Thanks @traumflug.

    I’ve put the code at the bottom of the setMedia function just above the return true; line. Is that the best place for it or would you recommend putting it somewhere else?



  • Also, can you mark your comment as the correct answer please? Only being able to pick one’s own comments as answers is one of this forum’s more annoying features.


 

Looks like your connection to thirty bees forum was lost, please wait while we try to reconnect.