Question

How can I add a block to a region using Drush?

I'm using Drupal 7.0 and Drush 4.3.

Was it helpful?

Solution

The Drush extras project has commands for administering blocks.

Short instructions (following their README.txt):

  1. Install this Drush add-on:

    drush dl drush_extras
    
  2. Determine desired module name and delta of block, and the desired region name and weight for adding the block:

    drush block-show
    
  3. Add the block to the region:

    drush block-configure --module=block_module --delta=block_delta \
      --region=region_name --weight=-12
    

More instructions via:

drush help block-show
drush help block-configure
drush help block-disable

OTHER TIPS

I think you maybe asking the wrong question here. I think your question might be - "how do I automate deployments to include blocks being placed in regions"?

In this case you have a few options, I would recommend:

  • Use panels and the page manager (currently on alpha 3)
  • Add blocks to a page layout and get this exactly how you what it. Views etc can also be added to the layout
  • Export the pages to features (current just hit beta 2 for drupal 7)
  • The feature can optionally have dependencies on other modules that may provide blocks for you module
  • On deploy, revert the feature to enable the dependent modules and place the blocks in the right spot on the panel layout

I prefer this approach as it keeps your entire site layout in code, thus making it able to be stored in version control, and of course deployable to your production web servers with little hassle. Roll back is also made easy.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top