I have implemented a simple template system using Oscommerce 2.3.4. So that I can run multiple shops, with the potential to change the content or look of a shop on a 'site' or 'template' basis.
The core OSC files (module files, classes etc.) still reside in directories off the app root, but the templates, language files and stylesheets reside in 'templates' and 'sites' directories. Each 'template' or 'site' directory structure is the same as the standard structure of the OSC app. If a file is present in site / template folders it will be used instead.
There is a default template directory for all the default template and language files. The precedence for selecting which file to use goes like this:
- Look to see if there is a site specific file (sites/***/...).
- Else, look to see if there is a template specific file. (templates/***/...)
- Else, Use the file in the default template directory. (templates/default/...)
I am considering to use the set_include_path function to list each of these directories, mentioned above, to take advantage of a behaviour of the include_path as documented on php.net:
PHP considers each entry in the include path separately when looking for files to include. It will check the first path, and if it doesn't find it, check the next path, until it either locates the included file or returns with a warning or an error.
This seems almost ideal for my situation, however I couldn't find whether this was considered 'good' practice.
I was interested if there are any pitfalls of using this such as, a performance hit. Considering that a lot of includes will now look in 3 directories before finally finding the default template in the 4th location.
(Although is this any worse than using if(file_exists())
multiple times which is the alternative.)
Also it will be necessary to set these include paths in the top of the app as the paths use variables for current site and template from the app. So i can't set the include path in the php.ini
Any help or advice much appreciated