Hi all,
I feel like I’m missing something simple here. Wouldn’t be the first time!
When adding an anchor [eg, #anchor1] to a non-home page [eg, about] via the TinyMCE RTE link editor - the resultant link points to:
https://domain.com#anchor1
instead of:
https://domain.com/about#anchor1
So all anchors created point back to the home page.
This happens whether you generate the anchors in the TinyMCE RTE link editor or by manually inserting them in the Content field.
The following tag exists on all pages:
<base href="https://domain.com/" />
I know I could override this by pointing to [[~[[*id]]]]#anchor1
but I can’t expect users to do this.
Thanks in advance for any thoughts.
Chris
EDIT
accidentally prematurely closed the topic before I posted my thanks to @jako for his solution:
@jako - apologies I’ve only just got round to looking properly at this.
Your solution works great.
My final code is as follows and the plugin fires on the OnWebPagePrerender system event:
if ($modx->resource->get('id') != $modx->config['site_start']) {
$modx->resource->_output = preg_replace('/(href=(\'|"))(#.*?\2)/', '$1' . rtrim($modx->makeUrl($modx->resource->get('id'), "", "", "full"), '/') . '$3', $modx->resource->_output);
}
Thanks as always for your help!
Chris