{anchor} tag on news pages

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
JamesT
Forum Members
Forum Members
Posts: 175
Joined: Tue Sep 08, 2015 10:41 am

{anchor} tag on news pages

Post 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?
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: {anchor} tag on news pages

Post 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.
JamesT
Forum Members
Forum Members
Posts: 175
Joined: Tue Sep 08, 2015 10:41 am

Re: {anchor} tag on news pages

Post 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.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: {anchor} tag on news pages

Post 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.
JamesT
Forum Members
Forum Members
Posts: 175
Joined: Tue Sep 08, 2015 10:41 am

Re: {anchor} tag on news pages

Post 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
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: {anchor} tag on news pages

Post 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.
JamesT
Forum Members
Forum Members
Posts: 175
Joined: Tue Sep 08, 2015 10:41 am

Re: {anchor} tag on news pages

Post 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?
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: {anchor} tag on news pages

Post 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.
JamesT
Forum Members
Forum Members
Posts: 175
Joined: Tue Sep 08, 2015 10:41 am

Re: {anchor} tag on news pages

Post by JamesT »

I think I'll write a custom UDT for this.

Thanks for your help!
Post Reply

Return to “CMSMS Core”