ModularMerchant
Knowledge Base
Shopping Cart Software Online Manual
Can QuickCode Tags Be Used in PHP Statements?
Adding a Company Name field to the storefront Can QuickCode Tags be used on non-store webpages?
Location Home > Shopping Cart Software Components > Administration Area > Design > FAQs & Tutorials

Can QuickCode Tags Be Used in PHP Statements?

question
I'm using a QuickCode Tag to try and reference a category's ID number in a PHP script. However, it's not working. The PHP code looks something like this:
<?php
if ({CATEGORY-SID} == 123) {
   echo ('You are viewing category 123.');
}
?>

What am I doing wrong? Can QuickCode Tags be used in PHP code this way?

The short answer is, no, QuickCode Tags cannot be used within PHP code in this way.

Why not?
Well, let's use the {CATEGORY-SID} QuickCode Tag as an example. This, and all other, QuickCode Tags are designed to be replaced by their source code prior to the web page that contains them being rendered in a web browser. That way, the QuickCode Tag provides a simple way to add blocks of complex HTML, JavaScript or PHP code without the need to fiddle with that code directly.

So, what is the source code that the {CATEGORY-SID} QuickCode Tag is replaced with? Is it the category's SID (System ID) number of "123"?

Nope. The {CATEGORY-SID} QuickCode Tag is actually replaced with the PHP code that it contains. In this case, any instances of this QuickCode Tag in the store's template are replaced with PHP code similar to:

{CATEGORY-SID} quickcode tag source code
<?php echo($category['id']); ?>

That means that example code from the original question would be translated by the shopping cart software into something like this:

example
<?php
if (
<?php echo($category['id']); ?> == 123) {
   echo ('You are viewing category 123.');
}
?>

See the problem there? Since the QuickCode Tag is replaced by its PHP source code, it results in a PHP tag nested within the other PHP tag, which will cause the PHP script to fail.

Fortunately, the solution is pretty simple.

The online QuickCode Tag glossary contains every QuickCode Tag available and the source code for each one. To fix the example script above, first look up the {CATEGORY-SID} QuickCode Tag in the glossary, and then use the desired content from the tag's source code in the PHP scripts.

We could then use the proper variables that we obtained from the "source code" section of the QuickCode Tag's glossary entry to create a correct version of the PHP script, which would look something like this:

example
<?php
if (
$category['id'] == 123) {
   echo ('You are viewing category 123.');
}
?>


— Last Edited - 12/23/2011 3:17pm PST
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 Merchant.com Homepage

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

Other articles in this category...

Add "Search by Price" links to the storefront

Add a "Terms of Service" agreement to a store page

Add a favicon

Add images to an email template

Adding a Company Name field to the storefront

Can QuickCode Tags Be Used in PHP Statements?

Can QuickCode Tags be used on non-store webpages?

Common customizations for the Order Receipt email

Copy a template package

Create a custom version of any QuickCode Tag

Create reusable headers/footer with Custom QuickCode Tags

Creating a Customer Registration Form

Creating templates with content viewable only by specific Customer Groups

Customize the category template to display subcategories in a grid

Customize the navigation header of a responsive template

Customize the navigation header of a responsive template

Customize the tabbed content area of a responsive product template

Disabling featured product display

Display a message if a customer has already purchased a product

Display a slideshow on any store page

Display sale prices in red text

Have your store match a website that links to it

Introduction to editing responsive template packages

Link your company logo to a different website

List of available Templates for use in Template Packages

Playing Flash video instead of downloading it

Require service agreement when a specific product is purchased

The difference between templates and web pages

Troubleshooting Missing Images

Untranslated Red QuickCode Tags

Using "Add to Cart" links on your website.

Using comments in Custom QuickCode Tags

Using the Custom Webpage Editor to add links to your Storefront

Your storefront on smartphones & mobile devices

Creating Template Packages: Part 1 of 4

Creating Template Packages: Part 2 of 4

Creating Template Packages: Part 3 of 4

Creating Template Packages: Part 4 of 4