Need some help with your project? Contact me

Cool module: Block Inject (new feature)

Update 23 September: I’ve been doing a bit of feature work on my module Block Inject. If you don’t know about the module yet, please see below what it does - there’s a screencast and everything.

7.x-1.2

This release makes Block Inject the most powerful it has ever been. If you are unhappy with the default placement of the injected region (middle of the body field), you can specify a number of paragraphs as an offset in any direction you want (up or down) to move it - on an individual node basis. Basically you now have the power to adjust it according to the content in that node.

The exceptions overview now includes information on the offset you have for individual nodes. It tells you whether the exception stops the injection or if it doesn't, how many paragraphs it is offset by.

Additionally, I fixed a couple of reported bugs, one of which now making it possible to use Block Inject on multilingual sites as well. It works both with the core translation solution and the Entity Translation module (which is the recommended approach).

So give it a try and let me know if you encounter any problems.

7.x-1.1

What I did in the 7.x-1.1 release was added the possibility to override the block region being injected into individual nodes. This means that if you set up a region to be injected in all the nodes of a type, you can then manually override this individually for each node. Let’s say if you are writing an article in which you do not want the injected block to appear, all you have to do is check a box.

To manually override this you have to edit a node and under the Publishing options you will see another checkbox: Remove the Block Inject effect on this node. If you tick this box and save the node, the region won’t be injected into this node. Naturally this checkbox will only be available for the content types for which there is a region to be injected.

Additionally, you get an overview page at admin/structure/block-inject/exceptions where you can see all the nodes for which the injection is exempted.

This new feature adds a bit more flexibility to the use of the module. Now you have the option that if for some reason a piece of content does not need the injection, you can prevent this from happening and know that for the rest of the nodes all is copacetic.

The alternative to this would have had you edit the block assigned to the injected region and set it to not display on a particular node page. But what if you have 3 blocks in the region and you need to stop them from showing on 15 nodes over time? With the new feature, everything is controlled at the node edit level and you also get an overview of which nodes are exempted from injection.

I want to work a bit more on making Block Inject even more flexible by allowing the site administrator to select into which text fields of a content type should the region be injected. Currently it goes into the body field by default but if your main text body is located in a custom field, the module won’t help you. So this will be a next step.

Probably after that, I will make it possible to override the placement of the injected region per node. Currently the default is in the middle of the node body field. This is done by calculating the number of paragraphs (<p>) and injecting it half way. However, it would be good to allow the content editor to move it up or down a couple of paragraphs for individual nodes if the situation requires it. Come to think of it, I might even work on this next :)

So if you can, test it out and fire up the issue queue with bugs and problems you may have - after all, the module is still in its alpha stage.

Block Inject - What Is It?

Block Inject is a simple module that lets you create custom block regions that get inserted automatically in the middle of all the nodes of a certain type. The idea for it stems from a previous article of mine in which I talked about how you can add content in the middle of the node body field.

It is very simple to use: you create a region to which you assign one or more node types. Then, you add blocks to that region with whatever content you want. These blocks will then appear in the middle of all the node bodies of the content type you assigned to that particular region. There is also a fail-safe: if the body field does not contain at least 2 paragraphs, no blocks get injected. Pretty cool and simple.

And of course, you can individually overwrite some things in the block configuration - for instance make the block display only for certain roles, on certain paths etc.

So do check it out, test it, let me know if you find any bugs or something.

Thanks a lot!

Comments

Thank for this great module. We are waiting for such module. Having Ads inside the Body field is nice trick. I already posted an article about Placing ads inside an article with Block inject in my blog to the Drupal french community to do our best to contributing in the issues.

Thanks for the support and comment!

You'll be pelase to know that this was perfect for a very big project we're working on right now. It's a port of an existing large news site to Drupal and they a newsletter subscription block buried in the body of every page. It'll be a couple months before the site is done, but you save us a headache with this one. :-)

Hehe, glad to do it!

Thanks for your comment!

Hello Danny. Great job! It's almost fantastic, but how i can set paragraph? I don't want put ads only in middle on my article. What do you think?

Hey there,
Thanks for the interest in my module. As I mention in the article, the latest release I created the possibility to override the placement of the ad per individual node. So you can choose to bring it higher or lower by a number of paragraphs.

D

I have 7.x-1.2-alpha2 version, but i can't override the placement of the ad per individual node. Where is it this feature?

Did you have a previous version before and upgraded to this one? If so, did you run the database updates and everything?

The place to override the placement is on the node edit form. When you add/edit a node of the content type for which there is a injection.

D

Thanks for adding this module, didn't know it existed and it is exactly what I am looking for

Great decision! Thank you, this is the right module!
On my site, widely used text formatting.
On those pages where applied paragraph formatting (eg <p class="rtejustify">), the block is not displayed. Can I fix it somehow?

Best regards, Sergey Shevgota.

Is there a possibility of making this inject a block based on the size of the browser? I am trying to get a DFP (ad) into the article if the screen is mobile-sized. Is this possible?

Not really at the moment. Can't easily get the screen size in PHP...

In Block Inject file block_inject.module delete a line 304 <div class = "clearfix"> </ div>
Then, using the module Block Theme, assign block style:
.insert {
float: right;
width: 37%;
max-width: 304px;
margin: 5px 0 5px 10px;
padding: 0;
}

Hi,
Your module is just what I needed and so easy to use! However, I'm trying to put adsense ads in multiple places within the content. Is that possible?

Thanks.

Add new comment

You can post comments in Markdown and basic HTML tags.
For code blocks, wrap your code within '~~~'. For example:
~~~
$var = 'my variable';
~~~