Zen Cart custom software development, Zen Cart modules, Zen Cart Expert eCommerce with Zen Cart!

Using Files Containing Boilerplate Text in the osCommerce Product Description

Relevance: osCommerce 2.2rc2a and forward. The same approach can be used in prior versions.

Donate: This is free software. Show your appreciation by supporting my efforts. Donate

Related: Using Boilerplate Text in the Product Description

Including entire files of boilerplate in the description can be done in a manner similar to that described in a prior tip called Using Boilerplate Text in the Product Description. However, instead of the keyword being replaced by a string, I'll show you how to replace a keyword with a file.

Create the directory
You will populate this directory with files whose names are <some-keyword>.html. For instance, suppose you have some text you want to add to all your DVD products. Create a file called DVD.html in this directory, i.e.
Put whatever HTML marked-up text you want in that file.

Now go to
  <p><?php echo stripslashes($product_info['products_description']); ?></p>

with this code:

function html_include_cb($match) {
      $prefix = "HTML_INCLUDE_";
      $match_filename = str_replace($prefix, '', $match[0]); 
      $filename = DIR_WS_LANGUAGES . $_SESSION['language'] .  
                 '/boilerplate/' . 
                 $match_filename  . ".html";
      $buffer = ""; 
      if (file_exists($filename)) { 
          $handle = @fopen($filename, "r"); 
          while (!feof($handle)) {
              $buffer .= fgets($handle, 4096); 
      return $buffer;
$products_description = $product_info['products_description'];
$pattern = "/HTML_INCLUDE_[a-zA-Z0-9]*/"; 
$products_description = preg_replace_callback($pattern, "html_include_cb", 
           $products_description, -1);
echo '<p>' . stripslashes($products_description) . '</p>';

Now to use this logic, all you need to do is enter HTML_INCLUDE_DVD in the product description (under Admin - Categories), and when you display the product info page, it will be changed. For any HTML_INCLUDE_SomeAlphanumericString you add to a product description, simply create a file called
and it will automatically be displayed. Note that the string really does have to be alphanumeric; don't use dashes, underscores, spaces or special characters in the name.

Although this tip describes the additive use of HTML Boilerplate, it can also be used to completely replace the product description which is entered in the osCommerce Admin Panel.