-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Anchor links to same page shows as broken #894
Comments
Thanks for reporting Amol. Could I get you to quickly find the exact versions of cms and elemental that you're running? You can do that with Cheers |
|
Hi Just adding my findings below if that helps in debugging the issue further. Anchors work fine when you select a different page on the "Link to an anchor on a page" popup modal form, but not when you select the same page. (Though doesn't throw any error in the console.) Adding below list of element module versions and their dependencies.
Cheers |
Core issue is that SiteTreeLinkTracking_Parser (which is used by the SiteTreeLinkTracking DataExtension, which DOES run on elemental blocks) assumes that page content is } elseif (!empty($matches['anchor'])) {
// Ensure anchor isn't broken on target page
$anchor = preg_quote($matches['anchor'], '/');
$broken = !preg_match("/(name|id)=\"{$anchor}\"/", $page->Content); // <<< here's your issue
} Seems like need to add quite a bit of API to do this properly, something along these lines: // SiteTree.php
public function getRenderedContent(): string
{
$renderedContent = [];
$this->updateRenderedContent($renderedContent);
$this->extend('augmentRenderedContent', $renderedContent);
return implode("\n", $renderedContent);
}
// protected to allow subclasses to override this i.e. NOT include $page->Content on BlockPage
protected function updateRenderedContent(array &$renderedContent): void
{
$renderedContent[] = $this->Content;
}
// BlockPage.php
protected function updateRenderedContent(array &$renderedContent): void
{
// noop
// i.e. don't include $this->Content
}
// ElementalPageExtension.php
public function augmentRenderedContent(array &$renderedContent): void
{
foreach ($this->[ElementalAreas] as $area) {
foreach ($area->Elements() as $element) {
foreach ($element->[HTMLText fields] as $field) {
// this is assuming that ALL HTMLText fields are rendered in templates, should probably have a
// private static array available on BaseElement to specify what HTMLText fields are rendered
$renderedContent[] = $element->$field;
}
}
}
} This would allow SiteTreeLinkTracking_Parser to use |
It's perhaps also worth noting there's the dream of a single 'content' API: silverstripe/silverstripe-cms#2454 |
Yup, that single content API is pretty much what's required here |
The root problem here is that anchors inside an elemental block are not properly supported. This will be resolved with #186, so I'm closing this issue in favour of that one. |
Issue:
Anchor links on internal or same page shows as broken.
My dev setup:
I am able to replicate this issue on basic Silverstripe site
My composer.json
To Replicate:
<p><a class="ss-broken" href="[sitetree_link,id=1]#anchor">Link to some anchor</a></p>
Related
#796
ACs
PRs
Note
The text was updated successfully, but these errors were encountered: