diff --git a/source/includes/_plugin_extending_pages.md b/source/includes/_plugin_extending_pages.md index 77918f3f423..632526de5ee 100644 --- a/source/includes/_plugin_extending_pages.md +++ b/source/includes/_plugin_extending_pages.md @@ -1,21 +1,53 @@ ### Extending Landing Pages +Make sure you reigster the event listener in your `config.php`: + +```php + [ + 'events' => [ + 'plugin.helloworld.page.subscriber' => array( + 'class' => PageSubscriber::class, + 'arguments' => [ + 'mautic.helper.templating' + ] + ) + ], + ], +]; + +``` ```php templating = $templating; + } /** * @return array @@ -36,8 +68,9 @@ class PageSubscriber extends CommonSubscriber public function onPageBuild(PageBuilderEvent $event) { // Add page tokens - $content = $this->templating->render('HelloWorldBundle:SubscribedEvents\PageToken:token.html.php'); - $event->addTokenSection('helloworld.token', 'plugin.helloworld.header', $content); + if ($event->tokensRequested('{myToken}')) { + $event->addToken('{myToken}', 'My Token'); + } // Add AB Test Winner Criteria $event->addAbTestWinnerCriteria( @@ -58,15 +91,18 @@ class PageSubscriber extends CommonSubscriber /** * Search and replace tokens with content * - * @param PageSendEvent $event + * @param PageDisplayEvent $event */ - public function onPageDisplay(PageSendEvent $event) + public function onPageDisplay(PageDisplayEvent $event) { // Get content $content = $event->getContent(); // Search and replace tokens - $content = str_replace('{hello}', 'world!', $content); + $html = $this->templating->getTemplating()->render( + 'HelloWorldBundle:SubscribedEvents\PageToken:token.html.php' + ); + $content = str_replace('{myToken}', $html, $content); // Set updated content $event->setContent($content); @@ -82,4 +118,4 @@ Page tokens are handled exactly the same as [Email Tokens](#page-tokens). #### Page A/B Test Winner Criteria -Custom landing page A/B test winner criteria is handled exactly the same as [page A/B test winner criteria](#page-a/b-test-winner-criteria) with the only differences being that the `callback` function is passed `Mautic\PageBundle\Entity\Page $page` and `Mautic\PageBundle\Entity\Page $parent` instead. Of course `$children` is an ArrayCollection of Page entities as well. \ No newline at end of file +Custom landing page A/B test winner criteria is handled exactly the same as [page A/B test winner criteria](#page-a/b-test-winner-criteria) with the only differences being that the `callback` function is passed `Mautic\PageBundle\Entity\Page $page` and `Mautic\PageBundle\Entity\Page $parent` instead. Of course `$children` is an ArrayCollection of Page entities as well.