Knowledge Base
Shopping Cart Software Online Manual
Using PHP includes in Templates
Override the default results per page
Location Home > Developer's Guide > Code Samples

Using PHP includes in Templates

this article last updated: July 17, 2012
Due to inevitable changes that will be made to the shopping cart software over time, the cart's variable and database structure may change from time to time without advanced notice. We will attempt to keep the information in this article up-to-date, but Modular Merchant makes no guarantee as to the accuracy of the information provided in this article. Use this information at your own risk.

Depending on your store design, you might find that you have specific content that you want to have appear on every page of your storefront. An example of this could be a navigation menu, footer or third-party traffic analysis tool.

To replicate this content on every storefront page, one approach could be to add the content to every single template used by your store. However, if you later want to change something in this repeated content, you'll have to edit every single template. That's a lot of maintenance for every little change that you want to make.

A way to avoid this maintenance nightmare is to place the repeated content in its own file, then use PHP to include that file on every page. That way, even though the content is repeated on every storefront page, its coming from one central file. Changes to the shared content can be done by editing just the one included file.

For example, you can use the following line of code to include the file "example.php", located in the "httpdocs" directory.

<?php include("example.php"); ?>

When a page with this code is opened, the contents of "example.php" will be added wherever the include() statement was placed in the template.

Note that the SEO-friendly URLs used by the shopping cart software can sometimes make determining the path to the included file a bit tricky.  You can avoid this problem by saving your replicated content in a custom QuickCode™ Tag. 

Then, instead of using PHP include() statement to insert the content into each template, use the custom QuickCode™ tag instead. Replacing the PHP include() with a custom QuickCode Tag, such as {CUSTOM-123}, precludes the need to specify a file path.

More articles on the subject of custom QuickCode Tags are available.

— Last Edited - 07/17/2012 4:15pm PDT
Rank and add a comment to this article
Only logged in users may leave comments and rank articles. Log in to have your say!
  Knowledge Base Home

  QuickCode™ Tag Glossary

  Modular Homepage

Not Logged in.
Either Log in or create a User Account.

Other articles in this category...

Can I add error messages to a storefront page?

Checkbox that adds additional products to the basket

Including additional variables in "Add to Cart" links

Override the default results per page

Using PHP includes in Templates