1

How can I copy blocks placement and settings between themes?

I've found this module: https://drupal.org/project/blockregion and this code to do it in the database. But both are for D6. How can I do this for D7

First, clear the existing block information for the new theme:

DELETE FROM blocks WHERE theme = 'NEW_THEME_NAME'

Now, copy all the block information from the old theme:

INSERT INTO blocks (module, delta, theme, status, weight, region, custom, throttle, visibility, pages, title, cache) (SELECT module, delta, 'NEW_THEME_NAME', status, weight, region, custom, throttle, visibility, pages, title, cache FROM blocks WHERE theme = 'OLD_THEME_NAME')

Also found this, but for D5: http://pierrerebours.com/blog/duplicating-block-settings-across-themes-drupal

2

I changed a little bit the code and it worked:

Before running this code you should be sure that both themes have the same regions and, if needed you will have to create the missing regionsin the new theme.

DELETE FROM block WHERE theme = 'NEW-THEME'

INSERT INTO block (module, delta, theme, status, weight, region, custom, visibility, pages, title, cache, i18n_mode) (SELECT module, delta, 'NEW-THEME', status, weight, region, custom, visibility, pages, title, cache, i18n_mode FROM block WHERE theme = 'OLD-THEME')
  • 1
    Don't forget to note that it may cause unexpected behaviour if you will insert blocks into regions that does not exist. Region list differ per theme and your query ignores it. It shouldn't cause WSOD, but may cause minor display glitches. – Mołot Feb 20 '14 at 13:39
  • You are right, I just first created the missing regions in the new theme. – chefnelone Feb 21 '14 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.