0

I have a block that I have configured to display "Only on the listed pages"

commerce_store/store/*

The problem is, it displays not only on the view link, which I want it to, but on the edit and other menu tabs

commerce_store/store/1        <-- good
commerce_store/store/1/edit   <-- bad
commerce_store/store/1/sales  <-- bad

I've tried switching to PHP code, but this doesn't seem to have any effect whatsoever. I've even changed the code to var_dump($path); exit; and it doesn't exit.

Edit: This code works, just enclose it in <?php and ?>

$path = current_path();
$url_parts = explode('/', $path);
if( $url_parts[0] == 'commerce_store' && $url_parts[1] == 'store' && count($url_parts) == 3 ) {
  return TRUE;
}
1

Note that you can use arg(x) where x is the position in the path starting from 0, so you could do something like this as well:

<?php
if (arg(0) . arg(1) == 'commerce_storestore' && !arg(3)) {
  return TRUE;
}
?>

You could also use drupal_match_path() like so:

<?php
if (drupal_match_path(current_path(), "commerce_store/store/*") && !arg(3)) {
  return TRUE;
}
?>

Cheers,

| improve this answer | |
  • I like the drupal_match_path solution, it seems the cleanest, though you were missing 1 argument which I added in. Thanks! – user11312 Dec 9 '13 at 5:25
0

Okay, dumb question. I didn't notice that <?php and ?> are required. Funky how they're required in some places and not in others. I guess I'll leave the question up in case the PHP code helps anyone else.

| improve this answer | |

Your Answer

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