1

I am developing a Drupal 7 theme. I want to change the position of the blocks when a user set my theme as default.

In my theme the main menu is positioned in left sidebar. Suppose the current theme of the user has main menu in the header block, when a user enables my theme, the main menu should go to the left sidebar.

Basically I want to position the block using code when my theme is set as default.

Any way to implement this?

  • Main menu should go "from" left sidebar "to" left sidebar, could this be some typo? Consider editing your question if needed ... – Pierre.Vriens Jun 16 '15 at 6:58
0

Only using Drupal core

Investigate the 'current theme of the user', to identify the 'region name' where the 'header block' (which contains the main menu) is positioned. Let's say that region is called "HeaderRegion".

Then in your own theme, make sure to create a region with the exact same name (like "HeaderRegion"), and position that region in the area that corresponds with what you describe as "left sidebar".

With this approach, the "main menu" will be shown in both themes in the block that is positioned in the "HeaderRegion"-region. And the actual theme that is selected will determine if it will be shown in the header (if using the current theme) or in the left sidebar (if using your own theme). Note: a "left sidebar" with a region name like "HeaderRegion" will sound a bit confusing, but that's a way to make it work ... (and maybe that region name in your current theme has a less confusing name, so you might be lucky and not suffer that confusion ...).

Using a contributed module

By using the Themekey module, you can implement content, user, or role -specific themes.

So if you can come up with the appropriate set of theme variations (which would differ by the location of your theme regions in which the blocks are displayed), this could be a solution that could work.

  • Thank you Pierre, I think Themekey do not work in my case. I do not want to use any contributed/custom modules. – Pramod Sivadas Jun 16 '15 at 7:26
  • Hm, that is crucial info that you should have included in your question. So consider enhancing your question to include that, maybe ALSO explaining why you want to make this work with only Drupal core (that's how I translate your comment). – Pierre.Vriens Jun 16 '15 at 8:09

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.