🧩 Templates, Hooks y Front — 6 modulos
#demoextendtemplates — Extender templates Twig (9.1+)
Nuevo en PS 9.1: demuestra las multiples opciones de extensibilidad de templates Twig en el BO. Cubre herencia, includes, bloques y hooks de template.
Este modulo usa funcionalidades de template disponibles solo desde PrestaShop 9.1.
github.com/PrestaShop/example-modules/tree/master/demoextendtemplates
{# 1. Herencia con extends #}
{% extends '@PrestaShop/Admin/layout.html.twig' %}
{% block content %}
{{ parent() }}
<div class="my-module-content">
{# Contenido adicional #}
</div>
{% endblock %}
{# 2. Include parcial desde modulo #}
{% include '@Modules/demoextendtemplates/views/templates/admin/partial.html.twig' %}
{# 3. Embed: include con override de bloques #}
{% embed '@Modules/demoextendtemplates/views/templates/admin/card.html.twig' %}
{% block card_body %}
<p>Custom body content</p>
{% endblock %}
{% endembed %}
{# 4. Hook renderizado en template Twig #}
{{ renderhook('displayAdminProductsExtra', { 'id_product': productId }) }}
#demovieworderhooks — Hooks pagina Ver Pedido
Demuestra como usar los hooks de la pagina Ver Pedido del BO, introducidos con la migracion a Symfony.
github.com/PrestaShop/example-modules/tree/master/demovieworderhooks
<?php
public function install(): bool
{
return parent::install()
&& $this->registerHook('displayAdminOrderMain') // Bloque principal
&& $this->registerHook('displayAdminOrderSide') // Columna lateral
&& $this->registerHook('displayAdminOrderTop') // Parte superior
&& $this->registerHook('displayAdminOrderTabLink') // Tab en la navegacion
&& $this->registerHook('displayAdminOrderTabContent') // Contenido del tab
&& $this->registerHook('displayAdminOrder') // General (legacy compatible)
&& $this->registerHook('actionGetAdminOrderButtons'); // Botones de accion
}
// Ejemplo: anadir un bloque en la columna principal
public function hookDisplayAdminOrderMain(array $params): string
{
$orderId = $params['id_order'];
$order = new Order($orderId);
$this->context->smarty->assign([
'order_reference' => $order->reference,
'custom_data' => $this->getOrderCustomData($orderId),
]);
return $this->display(__FILE__, 'views/templates/hook/admin-order-main.tpl');
}
// Ejemplo: anadir botones de accion al pedido
public function hookActionGetAdminOrderButtons(array $params): void
{
/** @var ActionsBarButtonsCollection $bar */
$bar = $params['actions_bar_buttons_collection'];
$orderId = $params['id_order'];
$bar->add(new \PrestaShop\PrestaShop\Core\Order\Actions\ActionsBarButton(
'btn-action btn-outline-secondary',
['href' => $this->getExportUrl($orderId)],
'Export custom data'
));
}
#demoproductextracontent — Extra content en producto FO
Anade contenido extra a la ficha de producto en el front office. Compatible desde PS 1.7.0.
github.com/PrestaShop/example-modules/tree/master/demoproductextracontent
<?php
use PrestaShop\PrestaShop\Core\Product\ProductExtraContent;
public function hookDisplayProductExtraContent(array $params): array
{
$productId = (int) $params['product']['id_product'];
$extraContents = [];
// Tab 1: Informacion adicional
$content1 = new ProductExtraContent();
$content1->setTitle('Informacion del fabricante');
$content1->setContent($this->getManufacturerInfo($productId));
$extraContents[] = $content1;
// Tab 2: Documentos descargables
$content2 = new ProductExtraContent();
$content2->setTitle('Documentos');
$content2->setContent(
$this->context->smarty->fetch(
'module:demoproductextracontent/views/templates/hook/documents.tpl'
)
);
$extraContents[] = $content2;
return $extraContents;
}
// Resultado: cada ProductExtraContent aparece como un tab
// en la ficha de producto del front office
#demooldproductpagehooks — Hooks producto antiguo (8.x)
Ilustra los hooks de la pagina de producto antigua (legacy). Solo disponible en la rama 8.x del repositorio. En PS 9.x se debe usar demoproductform en su lugar.
Este modulo solo existe en github.com/PrestaShop/example-modules/tree/8.x/demooldproductpagehooks. La pagina de producto legacy fue eliminada en PS 9.0.
#demofiltermodules — Filtrar modulos por hook
Demuestra como filtrar la lista de modulos que se ejecutan para un hook dado, basandose en el nombre del modulo. Util para control granular de que modulos participan en un hook.
github.com/PrestaShop/example-modules/tree/master/demofiltermodules
<?php
// Filtrar que modulos se ejecutan en un hook especifico
public function hookActionBeforeRenderingHook(array $params): void
{
$hookName = $params['hook_name'];
// Ejemplo: excluir modulos del hook displayHeader
if ($hookName === 'displayHeader') {
$params['module_list'] = array_filter(
$params['module_list'],
function ($moduleName) {
// Excluir modulos que no queremos en este hook
$excluded = ['ps_emailalerts', 'ps_sharebuttons'];
return !in_array($moduleName, $excluded);
}
);
}
}
#example_module_mailtheme — Mail theme custom
Demuestra como anadir un Mail theme completo a PrestaShop. Los mail themes controlan el diseno de todos los emails transaccionales.
github.com/PrestaShop/example-modules/tree/master/example_module_mailtheme
<?php
// Registrar el mail theme al instalar
public function install(): bool
{
return parent::install()
&& $this->registerHook('actionListMailThemes');
}
public function hookActionListMailThemes(array $params): void
{
/** @var ThemeCollectionInterface $themes */
$themes = $params['mailThemes'];
// Registrar nuestro tema de email
$themes->add(new FolderTheme(
'my_custom_mail_theme',
$this->getLocalPath() . 'mails/themes/my_theme/',
'My Custom Mail Theme'
));
}
// Estructura del mail theme:
// modules/example_module_mailtheme/mails/themes/my_theme/
// ├── core/
// │ ├── account.html.twig
// │ ├── account.txt.twig
// │ ├── order_conf.html.twig
// │ ├── order_conf.txt.twig
// │ └── ... (todos los emails transaccionales)
// └── components/
// ├── layout.html.twig # Layout base HTML
// ├── layout.txt.twig # Layout base texto
// └── header.html.twig # Componentes reutilizables
- BO — Pagina de pedido: demovieworderhooks - BO — Templates Twig: demoextendtemplates (PS 9.1+) - BO — Producto antiguo: demooldproductpagehooks (solo 8.x) - FO — Ficha de producto: demoproductextracontent - FO — Control de hooks: demofiltermodules - Emails: example_module_mailtheme