0

I have a block and I need to show this block only in some situations. For example if title of node includes "abc", block will be visible else it won't. From visibility settings of block I use this code snippet:

<?php
$match = FALSE;

$url = request_uri();
if (strpos($url, "myword")) {
  $match = TRUE;
}
?>

I'm sure that "myword" is included in full URL of node. I tried to debug it by adding "echo $url" but it didn't write this line into page.

How can I solve this?

edit: in last line i forgot to add "return $match;" which returned always false.

0

1 Answer 1

1

Try:

if (strpos($url, 'myword') !== FALSE) {
  $match = TRUE;
}

strpos() returns the zero-based index of the first occurrence of the substring.

So if "myword" is at the start of the URI string strpos() will return 0, and since 0 == FALSE in terms of a conditional, it will fail.

I've just tested your code and it works fine with the slight change.

Your Answer

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

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