Answers.Body: <p>This is impossible (not only in Craft, but in general) because the fragment (hash, the part after the <code>#</code>) is <strong>only used on the client-side</strong>. 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.</p>
  <p>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 <em>does</em> 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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-15T12:00:18.007Z
Answers.Text: Indeed, but this has nothing to do with my problem... Added hint that I use the param via javascript
Answers.UserDisplayName: Honsa Stunna
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-15T13:23:51.377Z
Answers.Text: @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.
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-15T13:37:07.720Z
Answers.Text: I need that url to go to the anchor depending on the object delivered from the craft db. Just as standard location hash https://developer.mozilla.org/en-US/docs/Web/API/Location/hash
Answers.UserDisplayName: Honsa Stunna
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-15T14:36:40.300Z
Answers.Text: I will use an additional field, thx for your help
Answers.UserDisplayName: Honsa Stunna
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-15T15:56:05.933Z
Answers.Text: @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.
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-15T17:49:40.593Z
Answers.Text: Onepager (section) with category anchors, open via switch or url with hash. Parent section childs with content of the categories is the "entry" or category overview. In this entry I want to define the default category. Easiest way i thought, adding the hash to the slug ;)
Answers.UserDisplayName: Honsa Stunna
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-16T10:21:47.587Z
Answers.Text: @HonsaStunna If it's a onepager, you can just use the entry slugs as fragments. Just output an ID based on the entry slug in your HTML code, then you can link to the specific sections by building a link with the slug as the fragment.
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-15T11:57:11.307Z
Answers.LastActivityDate: 2021-11-15T11:57:11.307Z
Answers.UserDisplayName: MoritzLost
Body: <p>I try to set the <strong>slug</strong> of an <strong>entry</strong> to a url using a hash.</p>
  <p><a href="https://url.spec.whatwg.org/#dom-url-hash" rel="nofollow noreferrer">https://url.spec.whatwg.org/#dom-url-hash</a></p>
  <p>However it seems not possible by default, craftcms changes the hash to a dash.</p>
  <p>I need that as fragment param for my javascript.</p>
  <p>I have searched and read the docs but cannot find any hint to change this behaviour</p>
  
Tags: <craft3><entry><url><slug><hash>
Title: DOM hash url in entry slug
ThreadText: # DOM hash url in entry slug
  
  (Asked by: username_0 on 2021-11-15)
  
  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
  
  **Tags:** craft3, entry, url, slug, hash
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-11-15. Score: 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.
  
  > **Comments:**
  > **username_0**: Indeed, but this has nothing to do with my problem... Added hint that I use the param via javascript  
  > **username_1**: @username_0 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.  
  > **username_0**: I need that url to go to the anchor depending on the object delivered from the craft db. Just as standard location hash https://developer.mozilla.org/en-US/docs/Web/API/Location/hash  
  > **username_0**: I will use an additional field, thx for your help  
  > **username_1**: @username_0 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.  
  > **username_0**: Onepager (section) with category anchors, open via switch or url with hash. Parent section childs with content of the categories is the "entry" or category overview. In this entry I want to define the default category. Easiest way i thought, adding the hash to the slug ;)  
  > **username_1**: @username_0 If it's a onepager, you can just use the entry slugs as fragments. Just output an ID based on the entry slug in your HTML code, then you can link to the specific sections by building a link with the slug as the fragment.  
  
  ---
  
  