There’s a lot of little things in Business Catalyst that make the solution so flexible, but many of them are unknown or unadvertised. In fact, it often takes a customer asking us: ”how do I use this to do that “ it dawns on us that that particular thing is actually possible! One such moment actually came about one day when Clinton (our intrepid designer) turned to Barry (a fellow support/development guy) and said:
“Hey Barry? If I want my images in my template to change as the page changes... Well what’s the proper way to do that?” Barry thought for a moment and said “You can’t do that.” Clinton then triumphantly said “Well, I’ve done it, but I think it’s a little dodgy... So I was wondering if there was a better way. See I used { module_pagename }.png as my image name, then named each image after the page it was supposed to match with.” By then I had started listening in, and started thinking about it. Barry sort of half smiled and remarked “That’s pretty clever! I didn’t think of that.... Of course that works!” We all agreed that was pretty neat, and started thinking of all the other things you could do with it...
And so, BC “Hacks” was born – a series of little tricks that are perfectly legal yet unintentional uses of modules and tags that are built into the system. { module_pagename } is one of those cool, unassuming things that works so well for so many things. There’s plenty more and I’ll introduce them all in this blog, in time.
Update: Please note there shouldn't be spaces after and before the curlique brackets { }. As our partner Jim has pointed out, the module works so well that when I originally wrote it in the post (without spaces) it got replaced with "BC Support Blog" :-) So I put the spaces in to stop it. Didn't think of
that, did I?
How It Works{ module_pagename } is pretty simple. Anywhere the Business Catalyst page processor finds { module_pagename }, it replaces the tag with the page name you’ve set in the page’s details tab. It doesn’t matter whether the page is in the template or the page itself.
Possible UsesYou can use it for anything that tickles your fancy, but most often we use it in a template when we want to make some element of the template change depending on the page the customer is looking at. Clinton used it as describe above, to make a particular template image change depending on the page being viewed.
More advanced uses of this module could be in javascript code, to do something dynamic depending on the page name - the possibilities truly are endless.
That’s all for today folks! Of course if you’ve got any great ideas for a post, any cool Hacks you’ve discovered or some nifty uses of this hack, leave them in the comments for us to pick up and show off.
Update: For Example... (added, by request!)
Let's say you want to change an image in your template depending on the page you are looking at, and you have three pages "Soap", "Shampoo" and "Conditioner". Let's also assume you want a picture in the template that changes to a picture of soap, shampoo or conditioner, depending on the page you are viewing.
So you name your images Soap_image.jpg, Shampoo_image.jpg, Conditioner_image.jpg.
Now go to your template and place one of your images on the template. Select Shampoo_image.jpg images. Now click on the image in the editor. At the bottom of the screen you'll see a button "Set Image Properties". Click on it and change the Image Src from :
/Img/Shampoo_image.jpg
To:
/Img/{ module_pagename }_image.jpg.
Click OK and then Save and Publish your template.
Now when the page is served to the browser, the source of the image will change to /Img/Shampoo_image.jpg or /Img/Conditioner_image.jpg or /Img/Soap_image.jpg, depending on which page we are on.
Neat :-)