Add A Block In The Center Of A Node’s Body Field In Drupal 7
- by admintech
Have you ever considered how to build a wall in the middle of your Body text? If your topic supports it, blocks may be added to the areas surrounding it; alternatively, you may use Display Suite to do so yourself.
You can’t make a block appear on each Article node in the middle of your Body. Not even with the Display Suite. If you’re familiar with .PHP, it’s not difficult at all. And, of course, if the node.tpl.php file doesn’t intimidate you, you’ll be able to find an easy solution on the Internet by searching for “drupal block body.”
But if you need something more dynamic, here’s another workaround. First, enable the core Context module. Then create a custom context that will display blocks around your Body text area. Here are the steps:
Go to Admin > Configuration > Context > Content types, and select all of your Article nodes. When finished, click Save configuration.
Next, go to Admin > Structure > Block layout. Select All regions (wrapper) under EXISTING BLOCK BODIES, click Add, and choose Page wrappers in the popup box. Under CONTEXT REWRITE METHODS, by default only Available contexts are selected; leave the default and hit Save block.
Next, go back to Admin > Structure > Blocks, and add a new block. Label it Body wrapper, set the Block type as Content (wrapper), select Article in Node or content for Display on-site? , and choose your new custom context under Page wrappers. Set the Number of columns to 1 and make sure to restrict each user role to see at most one item checked off. Under Show block on specific pages: check All pages (you can leave defaults here) and click Save block.
Now visit any Article node you created. You’ll notice that your body text area is contained within a box with rounded corners, like this:
Go ahead and enjoy using this workaround until Drupal core gets fixed! (And help other folks out by reporting the bug.)
After that, we should be able to use the default Views 2 implementation: View 1: Create a new view and set up your first View as you would for an HTML page and give it a Page title. Under Sorting and grouping, click on Content: Title. Then under Fields, click on Add next to filters. Check off Content: Type, then select Node from the list of available content types. Click Apply (all displays). Finally, check off Exclude under Filter criteria, so only Articles get returned.
You may not use a block as a content holder in the center of the Body. The node, article.tpl.php, may be customized by hard-coding the $added_string to anything you want. However, using a block in a region allows you to always return to the Drupal UI to reveal or hide that block based on various dependencies such as page, role, and even add extra blocks to that area.
Have you ever considered how to build a wall in the middle of your Body text? If your topic supports it, blocks may be added to the areas surrounding it; alternatively, you may use Display Suite to do so yourself. You can’t make a block appear on each Article node in the middle of your…
- SaaS Security Best Practices
- Your Short SaaS Security Checklist: From Development to Launch
- SaaS Security Risks Company Needs to Protect Against
- SaaS Security: Safeguarding Customers’ Privacy and Company Data in Subscription-Based Cloud Software
- Add A Block In The Center Of A Node’s Body Field In Drupal 7