diff --git a/README.md b/README.md index 5a2866b..0c3787e 100644 --- a/README.md +++ b/README.md @@ -58,3 +58,25 @@ services: setup: - Pd\AsyncControl\UI\AsyncControlLink::setDefault('Load content', {class: [btn, ajax]}) ``` + +## Search engines + +To allow indexing of your site by crawlers you need to add meta tag to your page. + +```latte + +``` + +> If you place into the page www.example.com, the crawler will temporarily map this URL to www.example.com?_escaped_fragment_= and will request this from your server. Your server should then return the HTML snapshot corresponding to www.example.com + +When parameter `_escaped_fragment_` is present in url `AsyncControlTrait` will always render its content. + +If you want the same behaviour for visitors of your page with disabled JS, add additional meta tag within noscript tag: + +```latte + +``` + +To avoid extra load on your servers and crawlers use these tags only on pages containing controls with trait `AsyncControlTrait`. diff --git a/src/UI/AsyncControlTrait.php b/src/UI/AsyncControlTrait.php index 4e7679b..e8eb75e 100644 --- a/src/UI/AsyncControlTrait.php +++ b/src/UI/AsyncControlTrait.php @@ -43,7 +43,11 @@ public function handleAsyncLoad() public function renderAsync(string $linkMessage = NULL, array $linkAttributes = NULL) { - if ($this instanceof Control && strpos((string) $this->getPresenter()->getParameter(Presenter::SIGNAL_KEY), sprintf('%s-', $this->getUniqueId())) !== 0) { + if ( + $this instanceof Control + && $this->getPresenter()->getParameter('_escaped_fragment_') === NULL + && strpos((string) $this->getPresenter()->getParameter(Presenter::SIGNAL_KEY), sprintf('%s-', $this->getUniqueId())) !== 0 + ) { $template = $this->createTemplate(); $template->link = new AsyncControlLink($linkMessage, $linkAttributes); $template->setFile(__DIR__ . '/templates/asyncLoadLink.latte'); diff --git a/src/UI/templates/asyncLoadLink.latte b/src/UI/templates/asyncLoadLink.latte index 597da0d..3f5e4b4 100644 --- a/src/UI/templates/asyncLoadLink.latte +++ b/src/UI/templates/asyncLoadLink.latte @@ -1,5 +1,5 @@
- + {$link->getMessage()|translate}