Here is what I would like to accomplish: 1. Add data attributes to block (for example: data-key="value") 2. Nice to have: add a text area to block config page where i can enter data attribute key-value pairs (one per line) and have them added to the block.

Any guidance is greatly appreciated


You will need to create a custom block using hook block info, hook block view and hook block configure. That last hook will let you as a form render array (see drupal form api).

The custom block system in drupal 7 isn't very good. If you need anything but the simplest HTML code then you should create your own blocks using the above hooks.


I actually just built a module to handle this specific use case, called Block Data.

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.