0

I have created a URL/menu item via hook_menu, and in the proprocess_html I'd like to get my item (last element in the URL) (/test) without using arg(0).

I can do it in PHP but I was wondering how it was possible to get this with drupal.

end(explode("/", request_uri()))

this code is actually bad, there could be URL such as ?test=ok

Cheers,

7
  • Why not using arg() ?
    – pbonnefoi
    Feb 26, 2015 at 15:20
  • let's say that on different branches I have a / more in the url so arg(0) become arg(1)
    – GwenM
    Feb 26, 2015 at 15:53
  • Do you know if your item is going to change ? like is it always going to be "test" ?
    – pbonnefoi
    Feb 26, 2015 at 16:08
  • Yes it will be always the same last argument in the URI http://%/%/%/test
    – GwenM
    Feb 26, 2015 at 16:12
  • 1
    I think arg() only starts where drupal is installed so it should work in your case.
    – pbonnefoi
    Feb 26, 2015 at 16:23

1 Answer 1

1
array_pop(arg());

will return the last component of the current Drupal path.

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.