Page 1 of 1

Custom Template

Posted: 02 Mar 2016, 00:57
by mathiass
Hello community!

Aimeos seems to me a very interesting project. But the documentation is a bit confusing when referring to overwriting views.

Someone has a tutorial or I could give a guide on how to do?

Thank you. :)

Re: Custom Template

Posted: 02 Mar 2016, 09:50
by aimeos
The views itself are pretty straight forward: Just HTML with alternative PHP syntax.

You have access to all data that has been assigned by the HTML client which renders the view as well as all data that has been assigned by parent HTML clients, e.g.

|Client/Html/Catalog/Detail/Standard
| => template: catalog/detail/body-default.php
| => assigns: detailProductItem, detailProductMediaItems, etc.
|- Client/Html/Catalog/Detail/Basket/Standard
| => template: catalog/detail/basket-body-default.php
| => assigns: basketStockUrl, etc.
|-- Client/Html/Catalog/Detail/Basket/Selection/Standard
| => template: catalog/detail/basket-selection-body-default.php
| => assigns: selectionProducts, selectionAttributeItems, etc.

In the template of the selection HTML client, you have now access to selectionProducts, selectionAttributeItems, basketStockUrl, detailProductMediaItems, detailProductItem. You should have a look into the templates and the HTML clients to find out which data they assign.

To access the data in the view, you can use

Code: Select all

$this->get( 'selectionProducts', array() );   // second parameter is the default value if not available
$this->selectionProducts;   // (throws an exception if not available)
Additionally, there are some view helpers available. They are located in:
https://github.com/aimeos/aimeos-core/t ... iew/Helper

To use the view helpers in the view, call e.g.

Code: Select all

echo $this->url( $target, $controller, $action, $params, $trailing, $config );
The example prints the generated URL for the given parameters. Use lower-case for all view helpers, i.e. "url()" for the view helper in the "Url" directory. The parameters for each view helper varies, so so should have a look into the interface or implementation of the view helper you want to use.

These are the view helpers that are available:
* block: Extend from parent templates like in Blade or Twig
* config: Access to the configuration settings
* content: Generate media URL
* csrf: CSRF security for form posts
* date: Localized dates
* encoder: Quoting output to avoid security breaches
* formparam: Generates values for the "name" attribute of input elements
* mail: Access to an e-mail message that can be filled
* number: Localized number format
* param: Access to get/post/url parameters
* partial: Renders the given sub-template
* request: PSR-7 request object
* response: PSR-7 response object
* url: Generates URLs
* value: Access values in multi-dimensional arrays in a simple way

Hope that helps a bit :-)

Re: Custom Template

Posted: 02 Mar 2016, 13:04
by mathiass
For Laravel is the same?

Re: Custom Template

Posted: 02 Mar 2016, 13:08
by aimeos
Yes, the templates are shared in all environments (Laravel, Symfony, Flow, TYPO3, etc.)

Re: Custom Template

Posted: 02 Mar 2016, 17:57
by aimeos
This article contains now detailed information and examples about the view helpers too:
https://aimeos.org/docs/Developers/Html ... iew_helper