Reusable sublayouts
We often want to use the same layout snippets in different views. For this purpose VM3 has sublayouts. Sublayouts are very similar to the Minilayouts of Joomla, but are more in flow oriented style for easy use.
The sublayouts are stored in the FE folder /component/com_virtuemart/sublayouts. You can add your own sublayouts into the core folder, or add/override them via template using /templates/yourtemplate/html/com_virtuemart/sublayouts
The first parameter is just the name of the layout=file to be called. The static call is just
echo shopFunctionsF::renderVmSubLayout('prices',array('product'=>$this->product,'currency'=>$this->currency));
The associative array is then available as $viewData.
or within a VmView
echo $this->renderVmSubLayout($this->productsLayout,array('products'=>$this->products,'currency'=>$this->currency,'products_per_row'=>$products_per_row,'showRating'=>$this->showRating));
The associative array is added to the context and useable for example as $this->products
Sublayouts can also be used to create your own userfields. The new TOS userfields is an example for it. Just select the userfield type custom. The name of the userfield is the used name of the sublayout. Take a look on the tos.php in /components/com_virtuemart/sublayouts.
Which layouts do appear in the configuration dropdowns?
The normal layouts do not appear in the dropdowns as option, if there is an underscore _ in the name. This is to prevent users to select only reusable parts of a layout. Despite to the normal layouts, any sublayout must have a unique name, because there is no related view for it. They are all stored in one folder. Therefore the different sublayouts of the same type or group are with underscore _ . So if you want to create a new sublayout for products and it shoud appear as choice in the vm config, the prefix must be "products_". See as example products_horizon.php.