1

I try to set the slug of an entry to a url using a hash.

https://url.spec.whatwg.org/#dom-url-hash

However it seems not possible by default, craftcms changes the hash to a dash.

I need that as fragment param for my javascript.

I have searched and read the docs but cannot find any hint to change this behaviour

2

This is impossible (not only in Craft, but in general) because the fragment (hash, the part after the #) is only used on the client-side. This is by design, it's part of the spec that the fragment is never sent to the server. The server never knows about the fragment, so it can't do routing based on it.

Using a fragment for routing is only possible if you have some sort of single-page-application which does routing in the frontend. In this case, the routing is done with JavaScript which does have access to the fragment, so it can route to a particular component based on it. Doing that on the backend (server-side) is impossible.

7
  • Indeed, but this has nothing to do with my problem... Added hint that I use the param via javascript Nov 15 at 12:00
  • 1
    @HonsaStunna Please expand on what you're trying to do. If you simply want to include a fragment in an URL somewhere on your site, you have to do that in your template where you output the link, not in the entry.
    – MoritzLost
    Nov 15 at 13:23
  • I need that url to go to the anchor depending on the object delivered from the craft db. Just as standard location hash developer.mozilla.org/en-US/docs/Web/API/Location/hash Nov 15 at 13:37
  • I will use an additional field, thx for your help Nov 15 at 14:36
  • 1
    @HonsaStunna Still curious about your use-case. If you describe your intended structure in more detail, I'm sure I can provide a good solution. But yeah, using an extra field sounds reasonable.
    – MoritzLost
    Nov 15 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.