Virtuemart Template System - A Guide
Virtuemart Template System - A Guide
Virtuemart Template System - A Guide
2
Users Guide
2
Introduction
2
Themes 2
Template Fields 3
Configuration Fields 3
Configuration 5
Shop Pages
6
Shop.index
7
shop.browse 9
recent.tpl.php (../templates/common) 11
featuredProducts.tpl.php (../templates/common) 12
1
VirtueMart Template System
Users Guide
Introduction
This, as the title suggests, is a users guide to VirtueMartʼs template system. It is not a guide to writing html,
php or css or for Joomla templates. Hopefully, it will show which templates each shop page uses and the
relationship between template files. This should make it easier for you to locate and edit the files required
to make your shop, look the way that you want it.
Some people may be dismayed that the files are not just plain html with a few extra tags added! But, using
a few php commands and following a few simple rules, quite complex shop pages can be made. With
some items only being displayed when they are required.
Themes
Each theme is stored in itʼs own subdirectory within VirtueMart. This means you can work on a new theme
and just switch for testing. Which means that you will always have a good theme to to back to.
For all these examples and explanations I shall be using the default template your-site/components/com_virtuemart/
themes/default.
The basic structure of each theme is as follows, I wonʼt go into detail about these files:
1. In the admin section certain defaults for the theme can be set. These values are stored in this file.
2. This stores all the css for the frontend of the store.
3. All javascript used by the theme are stored here. This can be extended with new functions for use by the theme.
4. Any php functions that the theme requires.
5. This displays the configuration settings in the admin section for the theme.
2
Within the templates are these folders:
Template Fields
If you want to output the value of a variable all you need to do is add PHP brackets and echo the variable
inside:
Don't forget to close the PHP brackets and always use valid PHP code. If you don't, it might break your
site.
Remember, you donʼt have to use all the available fields. It is up to you, the store owner or administrator,
as to which fields you display. Thatʼs the whole point of a template system, not just deciding where to
display your data but what data to display.
The following variables can be used in all of the template files without extra global declaration.
$VM_LANG
This is the global language object. It displays strings which are defined in the language file for VirtueMart.
Usage:
$sess
Usage:
Configuration Fields
These are the fields that are defined in the themes configuration. They are normally used to test for their
condition e.g. on or off, a list of styles etc.
3
Usage:
<?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not
allowed.' );
This stops the files being accessed outside of Joomla and must be included.
Each line of php must be ended with a semicolon unless it is a curly brace { or }
These braces are to define blocks of code e.g. a loop or an if statement. They must match otherwise the
page will fail and you may end up with a blank screen!
All VirtueMart code is written in an indented fashion. So each block of code and depth of the braces can be
easily seen. e.g.
<div>
<?php
foreach($something as $thing) {
//this is within the loop above
$command1 = $thing[“one”];
$command2 = $thing[“two”];
if($command 1 == $command2 ) {
//new block only executed if above is true
echo $command1.” “.$thing[“three”];
} //closes the true part of the if
else
{
echo “False”;
} // closes the else of the if
} //closes the loop
?>
</div>
as you can see comments can be added by using // and php code can be placed anyway. Itʼs just a case of
matching tags just as with html tags.
4
Configuration
There are three option in the product list style dropdown. This selects one of three alternative templates
when displaying the category pages. These define the overall look of the category pages.
Product List, no table, div based ../templates/browse/includes/ A basic div based layout
browse_notables.tpl.php
5
Shop Pages
Each page in a shop uses a backend file to generate all the data for the displayed page, each page will
call classes that help generate the data.
Each of these pages will populate the templates and may set data in several templates. The pages I will
deal with here are shop.index, shop.browse, shop.product_details and shop.cart. The page is shown in the
url of the page you are working on.
e.g. http://photography.noctilucent.me.uk/index.php?
page=shop.product_details&flypage=flypage.tpl&product_id=1&category_id=1&option=com_virtuemart&Ite
mid=53
As you can see page=shop.product_details is the file that generates the data for the page, so in the
VirtueMart core we know which page created the page and for any hacks or mods that require
customization will be done in this file. This wonʼt be covered here, but it gives you an insight on page
creation.
I will also cover the supplementary template files that each template uses. Several of these are shared
between pages. So they will only be covered once!
6
Shop.index
Shop.index is the first page of the shop, which displays a description of the shop and the top level categories.
Main files
7
Supplementary Template files used
Available fields
Field Template
$ps_product pointer to the ps_product class so that it can be used within the
templates.
$ps_product- This outputs the featured products using the pointer above.
>featuredProducts(true, The format is featuredProducts(random,no of products,categories)
10,false) i.e. random products - true, false, max number of products, category_id
to display, false.
Notes
There is nothing special to note about this template file. But to set the default number of categories per row
edit categoryChildlist.tpl.php This will be explained the Supplementary template files.
8
shop.browse
9
Supplementary Template Files
These files are not directly used to display pages, but are called by the main templates to keep a
consistent look and feel across the whole store. Many of these files will include some basic php to help
display the template. I will try to explain any significant lines to make it easier for you to customise.
categoryChildlist.tpl.php (../templates/common)
This file is used to display the sub-categories of the current category. It also checks the current categories
per row and if not set defaults it to 4. This can obviously be changed by editing the file.
For those that are not used to php, iʼll try to explain what each section does.
Line 6 $categories_per_row = 4;
This sets the default number of categories per row, changing the number obviously cahnges this.
This just checks to see if there are any sub categories, if not it just stops there and returns with an empty
category list.
This line sets up the link from the category list to the actual category displayed.
Available Fields
10
recent.tpl.php (../templates/common)
This template file displays the recently viewed products, the number of which is set in the configuration
page.
This just checks to see if there are any recently viewed products, if not it just stops there and returns with
an empty list.
These lines assign the field name to each recent product and then the value to that field name.
It may seem a little bit alien, but there is nothing to worry about. Just remember not to delete it or the loop
above. Basically, leave well alone, it works and thatʼs all you need to know.
This basically closes the loop started on line 8. So everything in between is done for each recent product.
Available Fields
Notes
The standard file just shows a list of the product name with a link then “Category” with a link to that
category. But the available fields allow more to be displayed e.g. a thumbnail which could encompass the
product name with a link to the product with the short description beside it without a link to the category.
It could also display the recent products across the page, not just in a list. It really is down to the store
owner as to how these are displayed.
11
featuredProducts.tpl.php (../templates/common)
This template file displays any product which has itʼs status flagged as special (featured product). It also
determines how many featured products to show per row. This template also use another template ../
templates/browse/includes/addtocart_form.tpl.php
line 2 $featured_per_row = 2;
Does what is says, sets the number of products to display per row.
This correctly outputs the thumb image in an image tag and resizes if necessary.
Available Fields
12
Field Name Description
13