Drupal Association members fund grants that make connections all over the world.
Block Content Per Role (sometimes referred to as Block CPR) provides configurable blocks, each with content to display for enabled & weighted roles.
Out of the box, Drupal allows blocks to be restricted to be visibible only to users with specific roles. There are some cases where a user may have more than 1 role (in fact, any user logged into a site already has 1 role, authenticated). If you were to add a set of blocks to a region and set each block to display for specific roles (for example, Anonymous, Authenticated & Subscriber) you would quickly run into problems as somebody logged in as a subscriber will also have an authenticated role.
Block CPR gets around this problem by letting the administrator "weight" the role's content. The first matching role from the visiting user will have it's content shown.
How do I use Block CPR?
After installing Block CPR, head over to the Block section in Site Building. You should see a new tab titled "CPR Blocks". This is where you configure the CPR Blocks by adding, editing and deleting them.
The Add and Edit form is exactly the same, however once you have setup a block you cannot change it's delta. The delta is the internal identifier for a block. The configuration form lists all roles configured on the site. By checking the box for a role, it becomes one of the "options" for selction. The weight drop down controls the order that each role is assessed. The blocks are ordered by weight in numerical ascending order (ie, -10 at the top, 10 at the bottom). Should two or more blocks share the same weight, the system will sort them by role name in alphabetical order. The content column allows you to specify content for a role. If a block administrator has permission to more than 1 input format, then they can select the format from the fieldset below the content block. Once you have saved the form, you can return to the block list page (the one which lets you move the blocks around the regions). You should now see your block in the list; if its a new block it will be in the Disabled section. You can move it to the preferred region.
What other modules work well with Block CPR?
I have found that the Token Filter module works well with this module. Token Filter exposes the popular Token module's functionality to content fields in the form of an input filter. Once Token Filter is enabled (and its dependency, Token) you can enable the filter on an existing or new input format. If you then use that format for one of the blocks, you can add some pretty user friendly functionality, for example:
- Anonymous (weight = 0):
Hi, why not <a href="/user/register">register</a> or <a href="/user">login</a> to get the most out of example.com!
- Authenticated(weight = 0):
Hi [token global user-name]! Did you know that becoming a premium subscriber lets you unlock lots more content?
- Subscriber (weight = -1):
Hi [token global user-name]! Thanks for being a valued premium subscriber. Head over to our <a href="/downloads">downloads section</a> to get your bonus content!
Some things to note:
- Every logged in user has the authenticated role, so it is important to use the weight system to allow other roles to be assessed before authenticated. Anonymous does not matter - an anonymous user cannot be any other role at the same time.
- The Token Filter module uses the synatax
[token *SCOPE* *TOKEN*]where
*SCOPE*can (at the time of writing) either be global or user (generally you'd best stick to global when used with this module, unless the block is being displayed on a user's profile page). The
*TOKEN*is the token defined by the Token module.