Update 03_Disable_Anchor_Links.md

Update example code for disabling anchors on a per-instance basis.  The previous code was unclear and statically called a non-static method on SSViewer  (presumably this was SS3 code)
This commit is contained in:
DorsetDigital 2019-04-16 21:22:27 +01:00 committed by GitHub
parent 6a2762662b
commit 321ef827b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,17 +37,19 @@ SilverStripe\View\SSViewer:
rewrite_hash_links: false rewrite_hash_links: false
``` ```
Or, a better way is to call this just for the rendering phase of this particular file: Alternatively, it's possible to disable anchor link rewriting for specific pages using the `SSViewer::setRewriteHashLinksDefault()` method in the page controller:
```php ```php
namespace Example\HashLink;
use PageController;
use SilverStripe\View\SSViewer; use SilverStripe\View\SSViewer;
public function RenderCustomTemplate() class ExamplePageController extends PageController
{ {
SSViewer::setRewriteHashLinks(false); protected function init() {
$html = $this->renderWith('My/Namespace/MyCustomTemplate'); parent::init();
SSViewer::setRewriteHashLinks(true); SSViewer::setRewriteHashLinksDefault(false);
}
return $html;
} }
``` ```