does anyone know if it is possible to have blocks just appearing on pages that i want them to?

thanks

david

www.justride.co.uk

Comments

veridicus’s picture

On the admin blocks page there's a column called Path. Fill that in with a regular expression matching anything after the base path. For example, I have a block I only display on the main page of my site. For the Path of that block I use "<^(|index\.php)$>" (without the quotes). That means it'll display for the root of the site and for index.php if not query string is passed ($ means end of string (or line?)).

There's another block I only want on my admin pages, so for its path I use "<^(admin)>". Any address starting with admin will display the block.

If you use "nice" paths you can use <^(node/view/1)> for a specific page or <^(index\.php?q=...> if you don't rewrite your paths.

---
Plenty of reasons to not use Microsoft software

terre’s picture

I've been trying to figure out a solution for only having blocks show up on certain pages - see http://drupal.org/node/12159 -- and the regular expressions only apply to the main forum, blog, etc pages where a list of content is supplied. Ex: yoursite.com/forum/# or yoursite.com/blog/#

But once you click on the actual content page then you seem to no longer have control over what goes on the page because everthing is a "node." (Unless you go in and alias *every* single forum or blog post which is not feasible. For the past year I've done this when posting a "story", assigning an alias to get the blocks to show where I want. I can't see doing that for every forum post or blog post or event post.)

View a forum entry - then the path is just yoursite.com/node/#

View a blog entry - then the path is just yoursite.com/node/#

View an event entry - then the path is just yoursite.com/node/#

So there is no way, using the reg expression on the blocks setup page, that I can specify which blocks should only be seen on forum pages or only on blog pages or only on event pages.

Any suggestions, please?

veridicus’s picture

You're correct. The only exception I know of are book nodes. You can get to them through the node paths or book paths. This is done all through code and not the mod_rewrite module. So I believe the only way to make forum nodes show up with a forum path would be to change code. Same for every other kind of node, of course. If you can get the links to have paths of "forum" or "blog" or whatever from code then mod_rewrite can be used to have them resolve to "node". Maybe this should be posted as a feature request so you won't have to do a custom edit.

---
Plenty of reasons to not use Microsoft software

moshe weitzman’s picture

book/view urls were deprecated in 4.5 everything is node/x where x is the id.

terre’s picture

Yep. Probably need to submit that as a feature request. I did try to make some changes in the code, but I failed at it as I don't really know enough to know what to do :) .

lazydave21’s picture

it works perfectly, i didn't realise they solution would be so easy

amen to drupal:)

veridicus’s picture

Oops, just noticed the strings are invisible because the browser thinks they're tags.

For a block to appear on only on the main page: <^(|index\.php)$>
For a block to only appear on admin pages: <^(admin)>

---
Plenty of reasons to not use Microsoft software

pamphile’s picture

I'm know absolutly nothing about those regx strings.

Can anyone post the 4.5 regx strings they use for blocks. And I'm sure we can do better than this...

terre’s picture

<^(?!blog)> to not show on page with blog in the path name
<^blog> to only show on pages with blog in the path name
<^(?!admin|search)> not on admin or search pages

these will work for you on pages that actually contain those terms in the path - excellent for not showing stuff in the admin section.