| |||||||||||||||||||||||
| |||||||||||||||||||||||
| Themes and Templates |
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.
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 |
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.
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.
| Variable Name | Description |
|---|---|
| $product_name | The Product Name |
| $product_sku | The Product SKU |
| $product_s_desc | The Product Short Description |
| $product_description | The Product Description |
| $product_weight_uom | The Product Weight's unit of measure |
| $product_length | The Product Length |
| $product_height | The Product Height |
| $product_width | The Product Width |
| $product_lwh_uom | The Unit of Measure for the Product Length,Width,Height |
| $product_url | The Product URL |
| $product_in_stock | The Number of Products in Stock |
| $product_availability | The 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_data | An 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_special | Y or N, is the product on special? |
| $product_discount_id | The Product's Discount ID |
| $cdate | The Product's Creation Date (UNIX Timestamp) |
| $mdate | The Product's last Modification Date (UNIX Timestamp) |
| $product_sales | The Number of Sales of this Product |
| $product_unit | The Product's Packaging Unit |
| $product_packaging | The Number of Products per Package |
| $product_price_lbl | The price label; "Price:" |
| $product_price | The completely formatted product price |
| $product_packaging | Product Packaging information |
| $file_list | The list of additional files for this product (when the product has files assigned to it) |
| $addtocart | The Add-To-Cart Button Code |
| $product_type | Product Parameter Values |
| $product_reviews | The List of Product Reviews |
| $product_reviewform | The Form to post a new Product Review |
| $product_image | The small product image; complete image tag; wrapped into an URL when available. |
| $product_full_image | The relative filename of the product full image (relative to /components/com_virtuemart/shop_image/products/ |
| $product_thumb_image | The relative filename of the product thumbnail image (relative to /components/com_virtuemart/shop_image/products/ |
| $buttons_header | The PDF, Email and Print buttons |
| $navigation_pathway | The pathway to the product (Power Tools ? Outdoor Tools ? Chain Saw) |
| $more_images | The link to the "Product Images" page when the product has additional product images |
| $manufacturer_link | The link to the manufacturer info page |
| $vendor_link | The link to the vendor info page |
| $edit_link | The link to the product form of this product (admin only) |
| $ask_seller | The link to the "Ask a question about this product" page |
| $related_products | The list of related products |
| $navigation_childlist | The child categories for the current category (this product is located in) |
| $images | The object list of all additional images this product has |
| $files | The object list of all addtional files this product has |
| Variable Name | Description |
|---|---|
| $product_name | The Product Name |
| $product_sku | The Product SKU |
| $product_s_desc | The Product Short Description |
| $product_weight_uom | The Product Weight's unit of measure |
| $product_length | The Product Length |
| $product_height | The Product Height |
| $product_width | The Product Width |
| $product_lwh_uom | The Unit of Measure for the Product Length,Width,Height |
| $product_flypage | The internal Product URL (to the details page) |
| $product_url | The external Product URL |
| $product_in_stock | The Number of Products in Stock |
| $product_available_date | The fully formatted Product Availability Date |
| $product_availability | A String with the name of an image inside the availability images directory or a custom string indicating the delivery speed ("24h") |
| $cdate | The Product's Creation Date (fully formatted) |
| $mdate | The Product's last Modification Date (fully formatted) |
| $product_price | The completely formatted product price |
| $form_addtocart | The Add-To-Cart Button Code |
| $product_rating | The average Product Rating |
| $product_details | The string "Details" |
| $product_full_image | The relative filename of the product full image (relative to /components/com_virtuemart/shop_image/products/ |
| $product_thumb_image | The relative filename of the product thumbnail image (relative to /components/com_virtuemart/shop_image/products/ |
| $images | The object list of all additional images this product has |
| $files | The object list of all addtional files this product has |
| $buttons_header | The PDF, Email and Print buttons |
| $browsepage_header | The heading, the category description |
| $parameter_form | The Parameter search form |
| $orderby_form | The sort-by, order-by form PLUS top page navigation |
| $navigation_pathway | The pathway to the product (Power Tools -> Outdoor Tools -> Chain Saw) |
| $navigation_childlist | The child categories for the current category (this product is located in) |
| $browsepage_footer | The footer with page navigation and result counter |
To being using templates, you need to get a copy of the global template object:
$tpl = vmTemplate::getInstance();
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!
$tpl->set( 'product_weight', $db_browse->f('product_weight') ); in order to get the correct value.
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;