20
Introduction to Drupal 7 Session 5.2 Blocks management 1 Course by Init Lab (http://initlab.org) Drupalist: Kalin Chernev

Introduction to Drupal 7 - Blocks management and contexts

Embed Size (px)

DESCRIPTION

Blocks management in Drupal 7. Visibility settings by pages, content type and roles. Going one level up on blocks management using the Context module.

Citation preview

Page 1: Introduction to Drupal 7 - Blocks management and contexts

Introduction to Drupal 7

Session 5.2

Blocks management

1Course by Init Lab (http://initlab.org)Drupalist: Kalin Chernev

Page 2: Introduction to Drupal 7 - Blocks management and contexts

Agenda

• Drupal blocks

• Regions

• Managing blocks the easy and quick way

• Managing blocks in contexts

• Case study – arranging your website blocks

2Course by Init Lab (http://initlab.org)Drupalist: Kalin Chernev

Page 3: Introduction to Drupal 7 - Blocks management and contexts

Drupal blocks

• A block is a generic term that is applied to any self-contained piece of content, menu, or code.

• They can be:

– System blocks: login block, search block, etc

– Modules blocks: latest news block, slideshow

– Custom blocks

– Programmatically build blocks (with coding)

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 3

Page 4: Introduction to Drupal 7 - Blocks management and contexts

Regions

• In order to place a block into a given place, you need to have a region for this

• Regions depend on the theme you’re using

• To check your theme regions, go to admin/structure/block and click on the Demonstrate block regions

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 4

Page 5: Introduction to Drupal 7 - Blocks management and contexts

Default Bartik theme regions

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 5

Page 6: Introduction to Drupal 7 - Blocks management and contexts

Managing blocks

• Managing blocks with the handles

• Using the drop-down options

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 6

Page 7: Introduction to Drupal 7 - Blocks management and contexts

Managing blocks

• From the contextual links in the front-end

• Then edit the block from the back screen

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 7

Page 8: Introduction to Drupal 7 - Blocks management and contexts

Blocks tips and tricks

• Removing block title

– The <none> short code

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 8

Page 9: Introduction to Drupal 7 - Blocks management and contexts

Blocks with configurations options

• Some blocks have configurations

– Menu blocks have list links and edit menu

– Views block have views configurations

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 9

Page 10: Introduction to Drupal 7 - Blocks management and contexts

Blocks visibility settings by Pages

• You can set whether the block will appear – only a given set of

pages– or on any pages, except

a given set of pages

• You can use <front> short code to target the home page

• We want the slideshow to be visible only on the home page for example

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 10

Page 11: Introduction to Drupal 7 - Blocks management and contexts

Blocks visibility by content types

• You can set instructions for a block to appear only when a given content type is seen

• In our case we don’t use this option, but you can use it when for example you want to show a relevant articles block only on news articles

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 11

Page 12: Introduction to Drupal 7 - Blocks management and contexts

Blocks visibility by roles

• You can also set a given block to be visible for a specific user roles only

• You can use this option for example to display a content management menu only for the Office Assistant user role

• Or you can use this settings to show content for Premium (Paying) users only, etc

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 12

Page 13: Introduction to Drupal 7 - Blocks management and contexts

Blocks visibility by users

• Very rarely used option

• It’s better to define the necessary blocks with your client preliminary and set the blocks for them

• Blocks management in the end is a pretty complex logic for a regular user

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 13

Page 14: Introduction to Drupal 7 - Blocks management and contexts

Blocks management with Context

• Another way to manage blocks is with the Context module• Advantages

– Contexts can be compiled in features– Contexts can be re-arranged with drag and drop from administrators

with the Admin module– Cleaner way to manage blocks– Clean categorization possible– More options than the default blocks management capabilities

• A bit not so advantages– You have to know what’re doing with a bit of though beforehand, or

you’re re-make contexts all the time– If you have more than 1 block in 1 region, separated in different

contexts, you don’t have control on the order of display of the blocks

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 14

Page 15: Introduction to Drupal 7 - Blocks management and contexts

Enabling Context and Admin modules

• Enable the Context core module

• Enable also the Context UI module to be able to configure contexts with user interface

• Enable the Admin module to be able to edit contexts with and inspector and drag and drop

• Go to admin/config/user-interface/admin to place the Admin options on the bottom right (because we have the Administration toolbar enabled on the top)

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 15

Page 16: Introduction to Drupal 7 - Blocks management and contexts

Let’s create some contexts

• We want the slideshow to be displayed on the home page only

• Go to admin/structure/context and click the “Add” link to create a new context

• Place slideshow_homepage for a name of the context, always make it machine readable

• Place a tag Home page for better categorization• Select a Path condition and add <front> in the field so

that the context is valid for the home page only• From the Reactions, place the slideshow views block in

the Features region, as we have it now

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 16

Page 17: Introduction to Drupal 7 - Blocks management and contexts

Homepage slideshow context

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 17

You can now switch off the block from the blocks management screen

Page 18: Introduction to Drupal 7 - Blocks management and contexts

Create a feature for your work

• Taking only the newly created context for the home page with the block should be enough

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 18

Page 19: Introduction to Drupal 7 - Blocks management and contexts

Time for questions

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 19

Page 20: Introduction to Drupal 7 - Blocks management and contexts

Contacts

Kalin Chernev

– E: [email protected]

– T: twitter.com/kalinchernev

– U: http://shtrak.eu/kalata

Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 20