AJAX handler in PHP section of partial

As I understand from the documentation the AJAX handler may be defined in PHP section of the partial (“To create an AJAX handler, define it as a PHP function the page, partial or layout PHP section…”). But when I do so, I obtain an error that “AJAX handler was not found”.

Is this a bug? Or may be I miss something…

Hi @AlexeyEfremenko

The {% ajaxPartial %} tag can be used for AJAX handlers in the PHP section of a partial. This adjusts the page lifecycle to make partials and their handlers available. Here is the documentation link:

Thank you very much!
I think, the link you gave me need to be put somewhere on this page, maybe near “partial” word. Because it is not clear that partials with AJAX handlers need to be injected to page in specific way.

Thanks for this useful feedback. We have added the following paragraph to this page:

Handlers defined by pages, layouts and components are all registered automatically. If you are calling a handler from inside a partial, use the {% ajaxPartial %} Twig tag, which adjusts the page cycle to register its handlers.

1 Like