Jump to content

php include a file in product description?

Recommended Posts

Hi, Any way to use the php "include" statement in the product description area? Many products will have the same description and I would like to be able to edit them all at the same time if needed without having to edit each product description individually. I tried the standard php include but the php tag gets commented out for security reasons I'm guessing. Is there a Smarty tag perhaps that would work? Thanks!

Link to post
Share on other sites

In a stock CubeCart, no.

You may notice that when creating/editing a document, there is an option to "Parse Smarty tags".

This feature can be easily ported over to creating/editing the product's description. Then, the Smarty {include} tag can be used.

Would you be interested in learning how to do this?

Link to post
Share on other sites

We will be making these changes:

* Edit admin skin for products by adding checkbox.
* Edit admin source for products by adding code to manage checkbox value. (None needed)
* Edit database CubeCart_inventory by adding column to store checkbox value.
* Edit Get Inventory Data to parse the product description.
* Edit language file to add "Parse Smarty tags in description". catalogue group, 'smarty_parse' key

In the admin template products.index.php, find:

<div><label for="product_depth">{$LANG.catalogue.product_depth}</label><span><input name="product_depth" id="product_depth" class="textbox number" type="text" value="{$PRODUCT.product_depth}"></span></div>

On a new blank line after, add:

<div><label for="product_parse">{$LANG.catalogue.smarty_parse}</label><span><input type="hidden" name="product_parse" id="product_parse" class="toggle" value="{$PRODUCT.product_parse}"></span></div>

In the file /classes/catalogue.class.php, near line 1064, find:


On a new blank line after, add:

$product['description'] = ($product['product_parse']==1) ? $GLOBALS['smarty']->fetch('string:'.$product['description']) : $product['description'];

In the file /language/definitions.xml, find:

<group name="catalogue">

On a new blank line after, add:

<string name="smarty_parse" introduced="6.0.0"><![CDATA[Parse Smarty Tags in Description]]></string>

Using an external database utility, modify the Inventory table by executing the following. If you want to have Smarty parse the contents by default, use one (1). Otherwise, use zero (0).

ALTER TABLE `CubeCart_inventory` ADD COLUMN `product_parse` TINYINT(1) UNSIGNED DEFAULT 1;

If your database collection of tables uses a table prefix, be sure to prepend it to the name of the table in the statement.

Bring a product up for editing, and view the General tab. If not already checked, check the box for "Parse Smarty Tags in Description". Then view the Description tab. Switch the editor to Source mode. Somewhere in the description HTML, add {"Testing"} and save the changes.

Clear the cache. View the product on the storefront.

The {"Testing'} is a Smarty tag that simply prints Testing. If the braces and quotes are visible, then Smarty is not parsing the content.

If this is all working, then we explore how to properly use Smarty's {include} tag.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...