How can I check for a specific directory in my URL? I need to display an image if I'm in http://www.mywebsite.com/displayimg/mypage but not if I'm in http://www.mywebsite.com/mypage... would it be something involving drupal_get_path?

  • What you exactly want to do ? please explain in a better way Sep 19 '14 at 9:46
  • 1
    what are 'displayimag' and 'mypage'? are they strings or ids? what? Sep 19 '14 at 9:46
  • displayimg is a directory in my website. If the page points to it, I need to find a way to get the info from the URL and instruct Drupal to display a particular img on my page (mypage).
    – Jane
    Sep 19 '14 at 9:48
  • Ok, you can do it by checking arg from the URL. see arg Sep 19 '14 at 9:51

You can use arg to check for URL arguments. In your case, the second argument has to be empty, so you can try something like this:

if (arg(0) == 'displayimg' && arg(1) == 'mypage') {
  // Do something meaningful.

Better to use block to display image. Use block visibility setting for displaying on specific URL.

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.