PropertiesShow Parent
Tags:   No tags associated yet.

You can search the whole VirtueMart Knowledge Base! Just type in your search keywords in the text box on the upper right of this page.

Using Themes and Templates

This information applies to VirtueMart 1.1 and greater.

Themes

Introduction

A theme is what defines certain parts of the look and feel of your shop. All installations of VirtueMart should start out with the default theme.You can change the Theme in the "Site" section of the configuration form. Usually there's only one theme available, so you can't switch.A good way to think of themes is as "plugins", which contain a collection of page templates, images, stylesheets, javascript and other files. While editing these files can be a bit technical, the layout is separated from the content allowing you to make and distribute your own themes.

Structure

Themes can be found in the directory /components/com_virtuemart/themes
of your VirtueMart installation. The internal structure of a theme is the following:

Directory/File Function
/admin.css the stylesheet for the frontend administration
/theme.config.php the configuration file for the theme
/theme.css the main stylesheet for the theme
/theme.js the main javascript controller for the theme
/theme.php the "controller" for the theme; used to declare functions and include stylesheets (and more!)
/theme.xml contains the theme configuration parameters and additional information
/images/ holds the theme images
/templates/ holds the template files that allow you to style and restructure the shop pages
/templates/basket/ holds the basket templates
/templates/browse/ holds the templates for the product listing page
/templates/common/ holds some commonly used templates, like the price display, pathway and the product snapshot
/templates/pages/ holds the templates or all other pages (e.g. 'account.order_details.tpl.php')
/templates/order_emails/ holds the order email templates as used when an order is placed
/templates/product_details/ holds the product detail templates

Theme Configuration

Introduction

Themes can be configured for better usability. Configuration parameters can be used to turn on and off certain parts in templates. The configuration parameters are defined in the file /components/com_virtuemart/themes/THEMENAME/theme.xml and follow the common parameter syntax for components, modules and mambots as used in Mambo >= 4.5.1 and Joomla! (Read more about the mosinstall parameter XML syntax).When a user chooses to configure a theme (Shop Configuration ? Tab "Site ? "Layout", these parameters are parsed and displayed in a nice form. Now the user can make changes to the configuration. The current configuration values are stored in the file /components/com_virtuemart/themes/THEMENAME/theme.config.php. This file is renewed with the new configuration values each time a user saves the theme configuration.

Use configuration values in templates

It's easy to get or set the value of a configuration parameter from inside a template. You just need to call $this?get_cfg( 'parameterName' ) to get the value for this parameter. Example from /templates/product_details/flypage.tpl.php

// Show the vendor link?
if( $this->get_cfg('showVendorLink', 1)) {
    echo $vendor_link;
} 
The second parameter let's you predefine a "default" value, which is used when the configuration file for this theme doesn't have a value for this parameter.

Templates

Introduction

Important: a template in VirtueMart has nothing in common with a "template" in Joomla!.
A template is a file holding HTML and PHP code for displaying a page or a part of it.
Example: the file /templates/product_details/flypage.tpl.php. It is used to display details of a product. !!Placeholders or Variables? You might want to know which placeholders or variables are available to style and display certain details...well that differs from template to template.
The reason for this is that all variables must be imported into the template before you can use them. Most important: there are no more placeholders like {product_name} as used in VirtueMart 1.0.x. All details are avalaible in PHP variables. So all you need to know is: which variables can be used in what template and how can I use them?!Use PHP in the template

If you want to output the value of a variable all you need to do is add PHP brackets and echo the variable inside: Print out the value of a variable

<p>Product Name:
<?php echo $product_name ?>
</p>
Don't forget to close the PHP brackets and always use valid code. If you don't it might break your site.

Predefined Global Variables

$VM_LANG
This is the global language object. It displays strings which are defined in the language file for VirtueMart. Usage: <?php echo $VM_LANG->_PHPSHOP_FLYPAGE_LBL ?> This would print "Product Details".
$sess
Used to print SEF-enabled URLs that can be used in links. Usage: <a href="<?php echo $sess->url( $_SERVER['PHP_SELF'] .'?page=shop.product_details&product_id='.$product_id ) ?>">Details...</a>

Predefined Variables for the Flypage / Product Details Template

Variable NameDescription
$product_nameThe Product Name
$product_skuThe Product SKU
$product_s_descThe Product Short Description
$product_descriptionThe Product Description
$product_weight_uomThe Product Weight's unit of measure
$product_lengthThe Product Length
$product_heightThe Product Height
$product_widthThe Product Width
$product_lwh_uomThe Unit of Measure for the Product Length,Width,Height
$product_urlThe Product URL
$product_in_stockThe Number of Products in Stock
$product_availabilityThe product availability information as provided by themes/default/templates/common/availability.tpl.php; includes the "number of products in stock" and the average delivery time;
$product_available_dataAn Array with the following indexes:
product_available_date => The Availability Date as Unix Timestamp
product_availability => A String with the name of an image inside the availability images directory or a custom string indicating the delivery speed ("24h")
product_in_stock => The number of products left in stock
$product_specialY or N, is the product on special?
$product_discount_idThe Product's Discount ID
$cdateThe Product's Creation Date (UNIX Timestamp)
$mdateThe Product's last Modification Date (UNIX Timestamp)
$product_salesThe Number of Sales of this Product
$product_unitThe Product's Packaging Unit
$product_packagingThe Number of Products per Package
$product_price_lblThe price label; "Price:"
$product_priceThe completely formatted product price
$product_packagingProduct Packaging information
$file_listThe list of additional files for this product (when the product has files assigned to it)
$addtocartThe Add-To-Cart Button Code
$product_typeProduct Parameter Values
$product_reviewsThe List of Product Reviews
$product_reviewformThe Form to post a new Product Review
$product_imageThe small product image; complete image tag; wrapped into an URL when available.
$product_full_imageThe relative filename of the product full image (relative to /components/com_virtuemart/shop_image/products/
$product_thumb_imageThe relative filename of the product thumbnail image (relative to /components/com_virtuemart/shop_image/products/
$buttons_headerThe PDF, Email and Print buttons
$navigation_pathwayThe pathway to the product (Power Tools ? Outdoor Tools ? Chain Saw)
$more_imagesThe link to the "Product Images" page when the product has additional product images
$manufacturer_linkThe link to the manufacturer info page
$vendor_linkThe link to the vendor info page
$edit_linkThe link to the product form of this product (admin only)
$ask_sellerThe link to the "Ask a question about this product" page
$related_productsThe list of related products
$navigation_childlistThe child categories for the current category (this product is located in)
$imagesThe object list of all additional images this product has
$filesThe object list of all addtional files this product has

Predefined Variables for the Browse Page / Product Listing Templates

Variable NameDescription
$product_nameThe Product Name
$product_skuThe Product SKU
$product_s_descThe Product Short Description
$product_weight_uomThe Product Weight's unit of measure
$product_lengthThe Product Length
$product_heightThe Product Height
$product_widthThe Product Width
$product_lwh_uomThe Unit of Measure for the Product Length,Width,Height
$product_flypageThe internal Product URL (to the details page)
$product_urlThe external Product URL
$product_in_stockThe Number of Products in Stock
$product_available_dateThe fully formatted Product Availability Date
$product_availabilityA String with the name of an image inside the availability images directory or a custom string indicating the delivery speed ("24h")
$cdateThe Product's Creation Date (fully formatted)
$mdateThe Product's last Modification Date (fully formatted)
$product_priceThe completely formatted product price
$form_addtocartThe Add-To-Cart Button Code
$product_ratingThe average Product Rating
$product_detailsThe string "Details"
$product_full_imageThe relative filename of the product full image (relative to /components/com_virtuemart/shop_image/products/
$product_thumb_imageThe relative filename of the product thumbnail image (relative to /components/com_virtuemart/shop_image/products/
$imagesThe object list of all additional images this product has
$filesThe object list of all addtional files this product has
$buttons_headerThe PDF, Email and Print buttons
$browsepage_headerThe heading, the category description
$parameter_formThe Parameter search form
$orderby_formThe sort-by, order-by form PLUS top page navigation
$navigation_pathwayThe pathway to the product (Power Tools -> Outdoor Tools -> Chain Saw)
$navigation_childlistThe child categories for the current category (this product is located in)
$browsepage_footerThe footer with page navigation and result counter

Using and "Fetching" Templates

Create a template object

To being using templates, you need to get a copy of the global template object:

$tpl = vmTemplate::getInstance();

Import variables into the template

If you want to use a certain variable in your template you must import it before!
Templates don't have the global scope. So all variables are not available in a template unless you "import" them.
This can be done using the set method from the controller file (e.g. "shop.browse.php"):

$tpl->set( 'product_name', $product_name );
## Syntax: $tpl->set( 'This_is_the_variableName_available_in_the_template', $theOtherVariable );
Please note: The variable $product_name is just an example. You must care to get the variables from the database!
The browse page offers an database object holding all important product information: $db_browse. So if you need to access the "product_weight" or whatever value, you need to call
$tpl->set( 'product_weight', $db_browse->f('product_weight') );
in order to get the correct value.

Parse the template

If you have finished importing all needed variables into the template object, you can "fetch" it using this syntax: Parse a template

$contents = $tpl->fetch( 'product_details/myFlypage.tpl.php' );
// Print out the contents
echo $contents;

// Alternative: Fetch a cached template (caches if no cached copy available and Caching is turned on)
$contents = $tpl->fetch_cache( 'product_details/myFlypage.tpl.php' );
// Print out those contents
echo $contents;