Twig Hooks & PDF Template

Use Twig Hooks to place or tweak the invoice UI in Admin/Storefront, and override the PDF layout for branding or legal content.

Twig Hooks

What they are. Twig Hooks are Sylius 2.x’s way to inject templates into specific places (they replace old Sonata/Template Events). You configure them under the sylius_twig_hooks key. Find out more here.

Where the plugin defines hooks. The Invoicing Plugin ships its own hook configuration in the repository: config/twig_hooks/ (see plugin source). Review these files to learn which hooks/blocks it registers and their priorities. (GitHub)

Override or move the invoice blocks (example)

Create or edit a config file in your app, e.g. config/packages/twig_hooks.yaml:

# config/packages/twig_hooks.yaml
sylius_twig_hooks:
  hooks:
    # Example: adjust placement/priority of an invoicing block on Admin Order show
    # (Use hook names from the plugin's config/twig_hooks/)
    'sylius_admin.order.show.content':
      invoices:
        template: '@App/Admin/Order/_invoices.html.twig'  # your custom wrapper/template
        priority: 30                                      # higher = rendered earlier

Find exact hook and block names by reading the plugin’s config/twig_hooks folder and/or:

bin/console debug:config sylius_twig_hooks | less

General Twig Hooks usage and options (blocks, priority, enable/disable) are documented here. (docs.sylius.com)

PDF layout/template

Plugin template path (source): InvoicingPlugin/templates/shared/download/pdf.html.twig (in the plugin repo). (GitHub)

Project override path (place in your app):

templates/bundles/SyliusInvoicingPlugin/shared/download/pdf.html.twig

Common customizations:

  • Header with your logo/company data (you can point to a path via an env/parameter, e.g. SYLIUS_INVOICING_LOGO_FILE).

  • Tax identifiers, legal footer, terms.

  • Translations, currency/locale formatting.

Good practice: keep styles print-friendly and test long names, multi-page orders, and different locales.

Quick checklist

  • Confirm hook names/blocks from the plugin’s config/twig_hooks directory, then adjust in your app configuration. (GitHub)

  • Override the PDF layout in templates/bundles/SyliusInvoicingPlugin/shared/download/pdf.html.twig. (GitHub)

  • Ensure wkhtmltopdf is installed and reachable so PDF changes actually render (see your Configuration → PDF Generator).

  • Keep custom hookables idempotent and use priorities to avoid clashes. See the Twig Hooks docs for patterns. (docs.sylius.com)

Last updated

Was this helpful?