Using Files Containing Boilerplate Text in the Zen Cart Product Description
Donate! Show your appreciation by
supporting my efforts.
Relevance: Zen Cart™ 1.3.0 - 1.3.9, 1.5.0.
Cost: Free, but
donation appreciated
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 your custom template
if you haven't already done so. We'll call the template "custom" in this example.
Create a customized copy of
includes/templates/custom/templates/tpl_product_info_display.php
(from
includes/templates/template_default/templates/tpl_product_info_display.php)
Create the directory
includes/languages/<your-language>/boilerplate
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.
includes/languages/<your-language>/boilerplate/DVD.html
Put whatever HTML marked-up text you want in that file.
Now go back to
includes/templates/custom/templates/tpl_product_info_display.php
Just before
<!--bof Product description -->
insert this code:
<!-- bof html description -->
<?php
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);
}
fclose($handle);
}
return $buffer;
}
if ($products_description != '') {
$pattern = "/HTML_INCLUDE_[a-zA-Z0-9]*/";
$products_description = preg_replace_callback($pattern, "html_include_cb",
$products_description, -1);
}
?>
<!-- eof html description -->
Now to use this logic, all you need to do is enter HTML_INCLUDE_DVD in
the product description
(under Admin - Catalog - Categories and Products), 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
includes/languages/<your-language>/boilerplate/SomeAlphanumericString.html
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.
If you want to do replacements from the database in your file, it's only a little more work.
Let's suppose you want to insert the actual product's name
into your boilerplate.
Change
if ($products_description != '') {
$pattern = "/HTML_INCLUDE_[a-zA-Z0-9]*/";
$products_description = preg_replace_callback($pattern, "html_include_cb",
$products_description, -1);
}
?>
<!-- eof html description -->
to
if ($products_description != '') {
$pattern = "/HTML_INCLUDE_[a-zA-Z0-9]*/";
$products_description = preg_replace_callback($pattern, "html_include_cb",
$products_description, -1);
$products_description = str_replace('%PRODUCTS_NAME%', $products_name, $products_description);
}
?>
<!-- eof html description -->
Now, in your boilerplate file, use %PRODUCTS_NAME% whereever you
want to have the product name inserted.
You can do other fields similarly.
This tip was developed in June, 2008, and was
first submitted to the Zen Cart Support Forum
here.
NB: Since this modification only changes the description text on the product info page, you must either not display description text on listing pages or
use this logic on any listing page where you wish to display description text.
For example, to turn off description display in New Products listing, go
to Admin->Configuration->New Listing and modify "Display Product Description", setting the value to 0 (off). To modify New Products to use this
boilerplate change, customize the file
includes/templates/template_default/templates/tpl_modules_products_new_listing.php
adapting the technique described here.
See
Using Boilerplate Text in the Product Description
for a more detailed discussion.
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
Zen Cart Admin Panel.
| Certificates of appreciation most welcome! |
|
|
If the information you learned reading this site is helping your store make
more money, please consider making a donation. Thank you!
|
Want more Zen Cart?
Tips and Tricks
Contributions
Extensions
Custom Software
Newsletter