Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Apress.Pro.Drupal.7.Development.3rd.Edition.Dec.2010.pdf
Скачиваний:
74
Добавлен:
14.03.2016
Размер:
13 Мб
Скачать
☆

CHAPTER 10 ■ WORKING WITH BLOCKS

Block Visibility Examples

Within the block administrative interface, you can enter snippets of PHP code in the “Page visibility settings” section of the block configuration page. When a page is being built, Drupal will run the PHP snippet to determine whether a block will be displayed. Examples of some of the most common snippets follow; each snippet should return TRUE or FALSE to indicate whether the block should be visible for that particular request.

Displaying a Block to Logged-In Users Only

Only return TRUE when $user->uid is not 0.

<?php

global $user;

return (bool) $user->uid;

?>

Displaying a Block to Anonymous Users Only

Only return TRUE when $user->uid is 0.

<?php

global $user;

return !(bool) $user->uid;

?>

Summary

In this chapter, you learned the following:

•What blocks are and how they differ from nodes.

•How block visibility and placement settings work.

•How to define a block or multiple blocks.

•How to enable a block by default.

238

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]