2

I am using an entry's slug as the anchor for a page.

How do I grab the anchor from the request? For example I want to get #article-one from /blog/#article-one

If it's not possible, is there a way to grab the full URI /blog/#article-one including the hash?

1 Answer 1

3

It depends on what you mean by "get" the hash anchor, but I'm assuming you're trying to get it in either PHP, Twig, or JavaScript.

It is physically impossible to get the #anchor part via PHP, since PHP never has access to that information. This SO thread describes the issue.

If you're trying to access the #anchor in Twig, you're probably out of luck there too. Twig is just a PHP parser, so you've essentially got the same problem.

All you can do is access it via JavaScript. In which case, there is nothing Craft-specific about it (see linked SO thread).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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