Skip to content

Commit 6f72d44

Browse files
authored
Merge pull request #1288 from scottcwilson/boilerplate
Boilerplate page
2 parents 264da01 + 119d22d commit 6f72d44

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
title: Boilerplate
3+
description: Using repeating blocks of text in your Zen Cart
4+
category: running
5+
weight: 10
6+
---
7+
8+
"Boilerplate" is a term that means "standardized blocks of text."
9+
10+
There's no need to re-type the same text in multiple places.
11+
Try these plugins to save time and make your life easier!
12+
13+
## Order Comments Boilerplate
14+
15+
This plugin allows you to reuse blocks of text to paste into the order comments field on the Order Details page.
16+
17+
[Order Comments Boilerplate](https://www.zen-cart.com/downloads.php?do=file&id=2222)
18+
19+
20+
## ShortCodes for Zen Cart
21+
22+
Styled after WordPress shortcodes, this plugin makes it easy for you to inject links to categories and products.
23+
24+
[ShortCodes for Zen Cart](https://www.zen-cart.com/downloads.php?do=file&id=2394)
25+
26+
## Define Page Anywhere
27+
28+
This plugin allows you to pull in define page content (which can be easily edited in your Admin) into any page in your cart, including the product info page under conditions you specify.
29+
30+
[Define Page Anywhere](https://www.zen-cart.com/downloads.php?do=file&id=2333)
31+
32+
## Boilerplate Text on your Product Descriptions
33+
34+
This set of instructions allows you to define a block of text once and use it repeatedly in product descriptions.
35+
36+
a) Create boilerplate defines
37+
38+
You will be defining your boilerplate strings in a file called `includes/languages/english/extra_definitions/my_defines.php` Each string will have a PHP "define" statement, and all the strings will be listed in an array. In this way, users can simply add and delete strings by editing this one file, rather than having to dig into the internals of Zen Cart.
39+
40+
We'll use a simple example:
41+
```
42+
<?php
43+
44+
$descr_stringlist = array("PHP_ONE_WEEK_DELAY", "PHP_TWO_WEEK_DELAY", "PHP_THREE_WEEK_DELAY");
45+
$GLOBALS['descr_stringlist'] = $descr_stringlist; // required for Zen Cart 1.5.8 only
46+
47+
define('PHP_ONE_WEEK_DELAY', 'These decals will be shipped in one week after receiving your order.');
48+
define('PHP_TWO_WEEK_DELAY', 'These decals will be shipped in two weeks after receiving your order.');
49+
define('PHP_THREE_WEEK_DELAY', 'These decals will be shipped in three weeks after receiving your order.');
50+
```
51+
52+
We've defined three constants and added each one to a list called `$descr_stringlist`.
53+
54+
b) Update your product info template
55+
56+
Edit the file
57+
`includes/templates/YOURTEMPLATE/templates/tpl_product_info_display.php`
58+
59+
Change
60+
```
61+
<!--bof Product description -->
62+
<?php if ($products_description != '') { ?>
63+
<div id="productDescription" class="productGeneral biggerText"><?php echo stripslashes($products_description); ?></div>
64+
<?php } ?>
65+
<!--eof Product description -->
66+
```
67+
68+
to
69+
```
70+
<!--bof Product description -->
71+
<?php if ($products_description != '') { ?>
72+
<div id="productDescription" class="productGeneral biggerText">
73+
<?php
74+
$stripped_products_description = $products_description;
75+
foreach ($descr_stringlist as $varname) {
76+
$stripped_products_description = str_replace($varname, constant($varname), $stripped_products_description);
77+
}
78+
?>
79+
<?php echo stripslashes($stripped_products_description); ?></div>
80+
<?php } ?>
81+
<!--eof Product description -->
82+
```
83+
84+
Now to use this logic, all you need to do is type `PHP_ONE_WEEK_DELAY` in your product description (under Admin - Catalog - Categories and Products), and when you display the product info page, it will be changed.
85+
86+
If you display the Description in any of the other lists (Product Listing, New Listing, Featured Listing, All Listing), you will need to modify code that handles the product description for listing pages (in `includes/modules/YOURTEMPLATE/product_listing.php`) in the same way. Alternately, you can just set "Display Product Description" to 0 on those screens (available under Admin - Configuration).
87+
88+
If you just want to add some boilerplate text based on category, product name, or some other field, you can do that too, without having to type it in to each product in the Admin interface. For instance, here's some logic that adds the string `CAT1_DESC` - which you have defined in the file `includes/languages/english/extra_definitions/my_defines.php` - to every product in category 1:
89+
90+
```
91+
<!--bof Product description -->
92+
<?php if (($products_description != '') || ($current_category_id == 1) ) { ?>
93+
<div id="productDescription" class="productGeneral biggerText">
94+
<?php
95+
$stripped_products_description = $products_description;
96+
if ($current_category_id == 1) {
97+
$stripped_products_description = $stripped_products_description . CAT1_DESC;
98+
}
99+
echo stripslashes($stripped_products_description);
100+
echo '</div>';
101+
?>
102+
<?php } ?>
103+
<!--eof Product description -->
104+
```
105+
106+
Adding boilerplate to every product whose name includes some specific string is similar, but instead of using a simple numeric equality check, a regular expression must be used. This code fragment will add `FISH_STR` to the product description of every product whose product name ends with the string " fish."
107+
```
108+
<!--bof Product description -->
109+
<?php
110+
if (preg_match("/.* fish$/", $products_name)) {
111+
$products_description = $products_description . FISH_STR;
112+
}
113+
if (($products_description != '') {
114+
echo '<div id="productDescription" class="productGeneral biggerText">';
115+
echo stripslashes($products_description);
116+
echo '</div>';
117+
}
118+
?>
119+
<!--eof Product description -->
120+
```
121+
122+
What if you really want to add links and not static strings? Well, this is done in a very similar way. Instead of using the static strings described above, in the file `includes/languages/english/extra_definitions/my_defines.php`, add the code
123+
124+
```
125+
<?php
126+
127+
$descr_stringlist = array("RED_LINK", "BLUE_LINK");
128+
$GLOBALS['descr_stringlist'] = $descr_stringlist; // required for Zen Cart 1.5.8 only
129+
define('RED_LINK', '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=2') . '">' . 'red cars' . '</a>');
130+
define('BLUE_LINK','<a href="' . zen_href_link(FILENAME_ADVANCED_SEARCH_RESULT, 'keyword=search+string')
131+
. '">' . 'something else' . '</a>');
132+
```
133+
134+
... and instead of using the PHP_*_WEEK_DELAY strings above, you would use one of these strings in your description.
135+
136+

0 commit comments

Comments
 (0)