Page 1 of 1

{anchor} tag on news pages

Posted: Sat Jan 22, 2022 8:26 pm
by JamesT
The {anchor} tag does not seem to be working on news pages. For instance:

{anchor anchor="section1" text="Section 1"}

when used on https://www.example.com/news1 creates:

https://www.example.com/#section1

instead of:

https://www.example.com/news1#section1

I have pretty URLs enabled, and {anchor} works fine on content pages.

What is the correct way of creating anchor links on news pages?

Re: {anchor} tag on news pages

Posted: Mon Jan 24, 2022 8:11 pm
by velden
It probably has to do with the <base href="..."/> tag which you get for free when using {metadata} in your page template.
You can either disable that base tag, check https://docs.cmsmadesimple.org/tags/cms ... tadata-tag (double check if everything still works as expected after doing that.

Or create absolute urls. You may be able to use {$entry->canonical} in the news detail template to do so. Didn't check.

Re: {anchor} tag on news pages

Posted: Mon Jan 24, 2022 9:57 pm
by JamesT
Thanks. I've experimented with showbase=false in the {metadata} tag before but I had some breakage.

Also, that {anchor} works ok on content pages but not news pages seems to disprove the <base> tag being the issue.

I shall investigate using {$entry->canonical} instead as suggested.

Re: {anchor} tag on news pages

Posted: Mon Jan 24, 2022 10:15 pm
by velden
Anchors are pure html so cmsms isn't actually involved here.
If anchors work on other pages it must be because the base tag isn't present or has a different href value there, the href value in the anchors have another setup or the specific page is the homepage.

An url to the real website, if public, would help to understand the problem.

Re: {anchor} tag on news pages

Posted: Mon Jan 24, 2022 10:17 pm
by JamesT
velden wrote: Mon Jan 24, 2022 10:15 pm Anchors are pure html so cmsms isn't actually involved here.
No, {anchor} is a built-in CMSMS tag: https://docs.cmsmadesimple.org/tags/cmsms-tags/anchor

Re: {anchor} tag on news pages

Posted: Tue Jan 25, 2022 8:18 am
by velden
Yeah, you're right regarding the anchor tag.

Seems it doesn't consider module actions, only content pages. And in case of frontend module actions, those are of displayed on a content page in the end and that is what {anchor} takes to build the anchor.

In this case I would build the anchor link by using

Code: Select all

<a href="{$entry->canonical}/#foo">foo</a>
Didn't test with pretty url but expect it to work. The forward slash may be redundant depending on your configuration.

Re: {anchor} tag on news pages

Posted: Tue Jan 25, 2022 1:42 pm
by JamesT
velden wrote: Tue Jan 25, 2022 8:18 am In this case I would build the anchor link by using

Code: Select all

<a href="{$entry->canonical}/#foo">foo</a>
Thanks, that works in the News-Detail template but ultimately the goal was to allow News editors to add {anchor} tags ad-hoc in the Edit Article area.

Can that be done?

Re: {anchor} tag on news pages

Posted: Tue Jan 25, 2022 6:41 pm
by velden
You could write a UDT to that for News articles if you expect editors will understand the difference between the two situations.
Or do the above combined with an Event on News article added/edited to replace {anchor... } with your custom UDT

Another option could be to use some JS to rewrite the anchor links within News articles client side.

Finally a feature request for extra functionality of the {anchor} tag can be filed in the Forge. Not sure yet if it is an easy fix.

Re: {anchor} tag on news pages

Posted: Tue Jan 25, 2022 10:46 pm
by JamesT
I think I'll write a custom UDT for this.

Thanks for your help!