| Chapter 3. Modifying the Layout |
| Prev | Next |
|---|
The most important part of the Layout of your Shop is the Joomla template (Joomlahut.com is a good start)!
Starting with version 1.1, VirtueMart offers to style the shop using 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 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.
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.A template in VirtueMart has nothing in common with what is 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
/components/com_virtuemart/templates/product_details/flypage.tpl.php.
It is used to display details of a product.
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?
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 PHP code. If you don't, it might break your site.
The following variables can be used in all of the template files without extra global declaration.
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".
Used to build (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>
The Product Name
The Product SKU
The Product Short Description
The Product Description
The Product Weight's unit of measure
The Product Length
The Product Height
The Product Width
The Unit of Measure for the Product Length,Width,Height
The Product URL
The Number of Products currently in Stock
The UNIX Timestamp for the Product Availability Date
Y or N, is the product on special?
The Product's Discount ID
The Product's Creation Date (UNIX Timestamp)
The Product's last Modification Date (UNIX Timestamp)
The Number of Sales of this Product
The Product's Packaging Unit
The Number of Products per Package
The price label; "Price:"
The completely formatted product price
The product price array (holding the product_price, product_currency and product_price_id
Product Packaging information
The list of additional files for this product (when the product has files assigned to it)
The formatted product availability information from themes/default/templates/common/availability.tpl.php; includes the "number of products in stock" and the average delivery time; template file: "common/availability.tpl.php"
The raw product availability data as array; holds the "product_id", "product_available_date" (unix timestamp), "product_availability" (the string pointing to an image or just a description), "product_in_stock" (number).
The Add-To-Cart Button Code
Product Parameter Values
The List of Product Reviews
The Form to post a new Product Review
The small product image; complete image tag; wrapped into an URL when available.
The relative filename of the product full image (relative to /components/com_virtuemart/shop_image/products/
The relative filename of the product thumbnail image (relative to /components/com_virtuemart/shop_image/products/
The PDF, Email and Print buttons
The pathway to the product (Power Tools ⇒ Outdoor Tools ⇒ Chain Saw)
The link to the "Product Images" page when the product has additional product images
The link to the manufacturer info page
The link to the vendor info page
The link to the product form of this product (admin only)
The link to the "Ask a question about this product" page
The list of related products
The child categories for the current category (this product is located in)
The object list of all additional images this product has
The object list of all additional files this product has
The Product Name
The Product SKU
The Product Short Description
The Product Weight's unit of measure
The Product Length
The Product Height
The Product Width
The Unit of Measure for the Product Length,Width,Height
The internal Product URL (to the details page)
The external Product URL
The Number of Products in Stock
The fully formatted Product Availability Date
The product availability information; includes the "number of products in stock" and the average delivery time
The Product's Creation Date (fully formatted)
The Product's last Modification Date (fully formatted)
The completely formatted product price
The product price array (holding the product_price, product_currency and product_price_id
The Add-To-Cart Button Code
The average Product Rating
The string "Details"
The relative filename of the product full image (relative to /components/com_virtuemart/shop_image/products/
The relative filename of the product thumbnail image (relative to /components/com_virtuemart/shop_image/products/
The object list of all additional images this product has
The object list of all addtional files this product has
The PDF, Email and Print buttons
The heading, the category description
The Parameter search form
The sort-by, order-by form PLUS top page navigation
The pathway to the product (Power Tools ⇒ Outdoor Tools ⇒ Chain Saw)
The child categories for the current category (this product is located in)
The footer with page navigation and result counter
First of all, the template object must be created as an instance of the class vmTemplate.
//Create an object of the class vmTemplate $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"):
## Syntax: $tpl->set( 'This_is_the_variableName_available_in_the_template', $theOtherVariable ); $tpl->set( 'product_name', $product_name );
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.
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;