When configuring a block to show only on listed pages, how do I refer to the pages? That is, what "name" or by what format do I refer to a page? I have paths enabled and have used the page alias (url, name, path or whatever I should call it), but that is evidently not correct. Thanks for any help.

Comments

steveadamo’s picture

If your intent is to only display a block on certain pages, you should use the Page specific visibility settings option on the block settings page.

If, for example, you selected the Show on only the listed pages option, and wanted your block to show up only on two pages, you could add these two lines:

blog
my-new-page

Those two entries represent specific "pages" on your site - your blog page, and your my-new-page page. If you wanted the block to appear on all blog related pages (blog/texas/august/blog-name), you could add another entry in the settings of

blog/*
vnxvnx’s picture

Thanks. That is what I want to do, and your suggestion of how to do it is indeed what I have been doing.

However, the block in question is not displayed on the named pages. It is displayed on the front page if I write `' in the "Show only on the listed pages" field. But it is not displayed on my paged called (named, aliased) `the_page_name' if I write `the_ page_name' in the "Show only on the listed pages" field. That is why I am at a loss.

Finbarr’s picture

Make sure that you have indeed checked the box that reads 'show only on the listed pages' and not that box that reads 'show on every page except the listed pages'.

vnxvnx’s picture

Yes, I made sure of that. Thanks. That is not the source of my problem.

sgprs’s picture

Gonna bump this because I'm having the same problem. I've developed several Drupal sites over the past year and have never had this problem. Now I'm doing a special project for myself and wanted to use Acquia Drupal. Don't know if that has anything to do with it or not.

Anyway, I am all too familiar with restricting a block to a certain page, but now it's just not working. The admin navigation block, for example, displays perfectly. But any block I or an added module created just will not show up on either sidebar. It will, however, show up in other regions, like content top and bottom... but just not in the sidebars.

What's the deal now? Never had this happen before.

andrewmonax’s picture

I generally have been using just;

blog*
user/add/blog*

ss_drupal’s picture

I'm seeing this malfunction myself.

I'm trying all the combinations of radio button settings and path constructions.

I've got
pathauto
administration theme (set to garland)
my own zen subtheme
frontpage (as yet unused)

I'm on drupal 6.14 pretty current on php & apache

this could bone my whole current project, which requires multiple themes and a slightly unusual layout.

I will add that adding custom pages to administration theme is also not working.

Weird weird weird.

sgprs’s picture

I found out my problem. I really should have thought of this earlier, but oh well.
My problem is that I didn't think to exclude the Page Specific Visibility block from the editor (in my case, FCK). So try that. Either exclude the path from FCK or switch to plain text and don't use the editor. The problem is that when using the editor, it strips out and adds certain things, like breaks, etc. That interferes with the path. So switch to plain text and enter, for example: page or page/* for all pages to be included or excluded.

This worked for me. Now, all blocks are being displayed where they should be.

Hope it helps!

Chris

havg’s picture

I had the same problem happeing to me and it was driving me crazy. None of the replies helped me out, but the last reply by sgprs made me thinking and led me to a solution, at least in my case:

Instead of starting the entry on the first line of the edit box, I entered first a return (just typed the Enter button of the keyb), then I typed in the page I wanted the block to show upon on the second line like this node/3 and then entered two more returns.

Et voila, my problem was gone. Apparantly adding these empty lines solved in preventing the editor from messing up the entered path.

Greets,
Hans

wwwoliondorcom’s picture

Hello,

I have the same problem, do you have any other idea to try ?

Thanks.

jdln’s picture

Anyone made any progress on this?

mojoyoyo’s picture

I found solution to this problem following your instructions.

Thanks.

Mark Foote’s picture

Hans, that worked for me. Crazy weird. -Mark

Maya_SH’s picture

thanks .. this worked for me like :)

astro87’s picture

"Show on only the listed pages" not work if I type aliases like:

my_page

but it work if I use node ID:

node/1
moonpm’s picture

This worked a treat - thanks astro87! Saved me time and effort, much appreciated.

drupy_moe’s picture

Secondly I am relieved that this worked and annoyed at the same time. I did a lot of really convaluted and complex solutions to try and fix this problem and that fact that this simple method worked urkes me.

Thanks anyway

beratcelik’s picture

Use the node number (e.g. node/5) instead of the given name (e.g. my_page) by you.
In order to learn the node number remove "URL alias" from the edit tab of your page, save and check the link of your page from the address bar (e.g. http://localhost/?q=node/5).

pradeep gowda’s picture

We can achieve this in multiple way. Tried this with custom theme preprocess hook and it worked for me.

function mytheme_preprocess_block(&$variables) {
 
 $target_block_id = 'YOUR_BLOCK_ID';
 $display_paths = [
   '/node/1',       // Example path
 ];
 if ($variables['elements']['#id'] === $target_block_id) {
   $current_path = \Drupal::service('path.current')->getPath();
   $current_path_alias = \Drupal::service('path.alias_manager')->getAliasByPath($current_path);
   if (in_array($current_path_alias, $display_paths)) {
     $variables['#access'] = TRUE;
   } else {
     $variables['#access'] = FALSE;
   }
 }
}