Notice: You are browsing the documentation for PrestaShop 9, which is currently in development.
You might want to read the documentation for the current version, PrestaShop 8. Read the current version of this page
Hook | displayProductExtraContent |
---|---|
Locations | FO |
Type | display |
Origin | core |
Aliases | |
Description | Adds new field / content to the FO product page |
Origin | File |
---|---|
classic | templates/catalog/product.tml |
core | src/Core/Product/ProductExtraContent.php |
core | src/Core/Product/ProductExtraContentFinder.php |
protected $hookName = 'displayProductExtraContent';
protected $expectedInstanceClasses = ['PrestaShop\PrestaShop\Core\Product\ProductExtraContent'];
This hook has been implemented as an example in our example-modules repository - demoproductextracontent.
This hook is a little more complicated than the other ones. It renders the provided content on the theme level. By default, it uses Bootstrap tabs to display it:
{foreach from=$product.extraContent item=extra key=extraKey}
<div class="tab-pane fade in {$extra.attr.class}" id="extra-{$extraKey}" role="tabpanel" {foreach $extra.attr as $key => $val} {$key}="{$val}"{/foreach}>
{$extra.content nofilter}
</div>
{/foreach}
In the front office, ProductController
fetches all extra content using a ProductExtraContentFinder
.
class ProductExtraContentFinder extends HookFinder
{
protected $hookName = 'displayProductExtraContent';
protected $expectedInstanceClasses = ['PrestaShop\PrestaShop\Core\Product\ProductExtraContent'];
The ProductExtraContentFinder
will look for modules hooked into displayProductExtraContent
with the corresponding existing method, and will expect ProductExtraContent
to be returned.
return (new PrestaShop\PrestaShop\Core\Product\ProductExtraContent())
->setTitle('example field')
->setContent('example content')
This content will be shown in a dedicated tab on the product page: