官术网_书友最值得收藏!

Controlling block visibility based on user role

This recipe details the steps involved in toggling block visibility based on which type of user is viewing the page. For example, a block displaying advertisements might only need to be visible for anonymous users and not for authenticated users.

Getting ready

For this recipe, we will be configuring the welcome message block which we created in an earlier recipe in this chapter, to only be visible to authenticated users.

How to do it...

Controlling block visibility is handled from the block administration pages as outlined in the following:

  1. Navigate to admin/build/block (Home | Administer | Site building | Blocks).
  2. Locate the block which needs to be configured—the Welcome message block—and click on the Configure link next to it.
  3. On the configure screen, scroll down to Role specific visibility settings.
  4. Check the box corresponding to the authenticated user role which should have access to the block.
    How to do it...
  5. Click on the Save block button at the bottom of the page to save the changes.

How it works...

Drupal maintains a table named block_roles which keeps track of role-specific settings for all blocks. Changes made to role settings on the block configuration page are stored in this table. When an anonymous user now visits the site, Drupal will not display the Welcome message block.

主站蜘蛛池模板: 丽江市| 广西| 蕉岭县| 固镇县| 昌邑市| 林甸县| 梁河县| 广饶县| 崇礼县| 广东省| 辽阳市| 晴隆县| 霸州市| 新邵县| 苗栗市| 尉氏县| 镇远县| 苏尼特右旗| 疏勒县| 乌拉特后旗| 铜梁县| 汽车| 固镇县| 郑州市| 旺苍县| 德江县| 和硕县| 宿松县| 崇义县| 兴业县| 湘西| 同心县| 印江| 彩票| 岳普湖县| 肃北| 曲松县| 渝中区| 晋城| 子长县| 卫辉市|