Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Boost is great, but as most site have banners on them that change constantly how could i implement some solution that would show different banners? Guess i could use adsense but what if i want to show banners from drupal node? Can i get them somehow with ajax maybe? For example, i would just show randomly one node(banner) from a view. How to do this?
Comments
Comment #1
mikeytown2 CreditAttribution: mikeytown2 commentedAjax is the way to do it; here are the directions on how to do it. In short ajax load a block
http://groups.drupal.org/node/24825
Let me know if you hit any snags, I'll help you along the way.
Comment #2
Marko B CreditAttribution: Marko B commentedJust what i needed, thanx man. :-)
I would need some help with understanding part where u described it in more complicated way. Ok there are 2 divs, but what do i do with PHP code, and JS code? How does JS code call PHP code? Or how does drupal_add_js() line call code below it? Please explain this to me as i dont see connections between and and confused by this. thanx
Comment #3
mikeytown2 CreditAttribution: mikeytown2 commentedGet it working the simple way first once you have that down; shifting the code into the more complicated way will be fairly straight forward. If your having trouble with the simple way let me know and I can help you figure it out. First step is to get what you want to display inside a block. Once there see if you can get the simple directions to work in your case.
Comment #4
Marko B CreditAttribution: Marko B commentedI did get it working simple way. But i have 3 banners on page so i would like to have one bootstrap not 3. So please some notes on complex way :-) thanx
Comment #5
mikeytown2 CreditAttribution: mikeytown2 commentedwhats the code inside each .php?
Comment #6
Marko B CreditAttribution: Marko B commentedi have 3 blocks
$region="some_var";
print views_embed_view('banneri','block_3',$region);
print views_embed_view('banneri','block_2',$region);
print views_embed_view('banneri','block_1',$region);
and i output them like this. So ok, i can put this into your php code, and change # for divs, but how do i call this php to put banners into this divs? where to put JS and how does this JS call PHP?
Comment #7
mikeytown2 CreditAttribution: mikeytown2 commentedCreate 3 Blocks. In first block's content place
Repeat for the next 2. Or place these divs in your template; in short we need some empty div's to target.
In one of the blocks or somewhere else (your custom module, ect...) add in this PHP code. This will call the external php file, which will load the json data into the DOM. This only needs to happen once.
Finally we need to create the ajax_blocks.php file. Place this in your webroot or change filename variable above to match its location. This is a cleaner way of doing this in your case.
I'm assuming that the blocks contents are being sent back when you call views_embed_view(). Let me know how this works for you. Doing a selective drupal bootstrap is something to look into if this takes too long to generate the code; another way is to cache the html in the variables table (what you can do with core stats block if enabled with boost); thus only requiring a database bootstrap and no render time (regenerate the blocks content on cron then).
Comment #8
Marko B CreditAttribution: Marko B commentedI think i get it now, will try it today probably, just what is this ETO stuff? :-)
Selective bootstrap sounds good way to go, will look further into it, if u know some links with custom bootstrap that i could use, please send :-)
thanx a lot Mike!
Comment #9
mikeytown2 CreditAttribution: mikeytown2 commentedtheres not a lot in terms of rolling your own boot strap process; I use this as my guide...
http://api.drupal.org/api/function/_drupal_bootstrap/6
ETO is heredoc syntax; looks like it should be EOT
http://php.net/types.string#language.types.string.syntax.heredoc
Comment #10
Marko B CreditAttribution: Marko B commentedthanx
Comment #11
mikeytown2 CreditAttribution: mikeytown2 commenteddoes this work for your case?
Comment #12
Marko B CreditAttribution: Marko B commentedStill not tested but will soon for sure. Having problem with boost and Fupload module. Stops working when Boost is on. Did disable JS and ajax caching but still problem occur when many images are uploaded. Will try to isolate this problem first then make this adjustment.
One question, was thinking that it would be nice to load banners when page is loaded, like on some onLoad handled if possible (not expert on JS and Ajax just guessing), what do u think about that idea, is it doable and does it have any sense?
Comment #13
mikeytown2 CreditAttribution: mikeytown2 commentedu try it yet? js is added at the footer so the dom should almost be fully loaded at this time.
Comment #14
Flying Drupalist CreditAttribution: Flying Drupalist commentedThis is great, but there should be an UI option to do this. Would be a killer feature imo.
Comment #15
mikeytown2 CreditAttribution: mikeytown2 commented@Flying Drupalist
This should be it's own module; call it ajax blocks. It doesn't depend on Boost and other page caches like Varnish and Core could use it. Just need to do a hook form alter of the block configuration page & add in a checkbox to ajax load this block.
Comment #16
Flying Drupalist CreditAttribution: Flying Drupalist commented@mikeytown2 if you can make this module I will kiss your feet. :)
Comment #17
Marko B CreditAttribution: Marko B commentedI never managed to try it out. Had many other problems with site i was hopeing to try this that i didnt try it so far :-(
But what u suggested seems good and should work :-) Hope i get to try it and turn whole site into boost before summer :-)
Comment #18
reynaldio CreditAttribution: reynaldio commentedI've tried #7 and it works like charms. but can we add a loading icon when ajax load the content? maybe a loading text. and is it possible to automatically load .js and .css required by contents?
Thanks,
Reynaldi
Comment #19
mikeytown2 CreditAttribution: mikeytown2 commentedWhat ever you place in this div
<div id="banner1"></div>
will be replaced by the ajax content so a loading icon or text could easily be put in there.Quick example
Loading the extra js and css is a lot harder to do
Comment #20
reynaldio CreditAttribution: reynaldio commentedhi, can you please put some example code on how to use selective bootstrap?
Thanks,
Reynaldi
Comment #21
mikeytown2 CreditAttribution: mikeytown2 commentedSelective bootstrapping is useful for a couple of things...
1. You have what you need in the memcache/apc/database pre-rendered.
2. You want to run a small bit of code from a module & you know what the requirements are.
3. You wish to write data to memcache/apc/database
This is what I use as my guide
http://api.drupal.org/api/function/_drupal_bootstrap/6
Example of 1 + 3 is in boost_stats.php
Comment #22
mikeytown2 CreditAttribution: mikeytown2 commentedhere's a better way ;)
In one of the blocks or somewhere else (your custom module, ect...) add in this PHP code. This will call the external php file, which will load the json data into the DOM. This only needs to happen once.
We need to create the ajax_blocks.php file. Place this in your webroot or change filename variable above to match its location. This is an even better way of doing this in comparison to #7.
So what I have here are 3 different views with 6 different blocks getting dynamically replaced. This will "re-render" the block updating it to the latest version direct from drupal.
What I'm thinking of doing next is hiding the block until its been updated & then displaying it. Which is similar to how #7 works; just this way it doesn't require a new element to be in the DOM, uses what's already there.
Comment #23
mikeytown2 CreditAttribution: mikeytown2 commentedhttp://drupal.org/project/ajaxify_regions is what I use now
Comment #24
Marko B CreditAttribution: Marko B commentedThanx Mikey, i will probably try it in few months in redesign of site i was working on before as i would like to use boost with it. Thanx for pointing it out.
Comment #26
srahul07 CreditAttribution: srahul07 commentedHi Following is my code:
I have created a block named: Items in cart which is having following code:
Also the file cart_items.php executes a custom block as seen above named: tuts_block which is as follows:
If I execute the cart_items.php file from browser it does show me the number of items in cart but in block Items it is showing blank. When I use Inspect elements in browser I can see that block is loaded and the above script call is coming as is as follows:
Please let me know where I am going wrong.
Comment #27
srahul07 CreditAttribution: srahul07 commentedNot sure how it got posted twice and now could not delete second one. It does show me that its cloed and fixed where as opened it again.
Please let me know about the issue expianed above: http://drupal.org/node/657826#comment-5580816
Comment #28
bgm CreditAttribution: bgm commentedDo you have an URL we can see to test? It will be difficult to debug otherwise.
Comment #29
bgm CreditAttribution: bgm commented(re-Closing issue, open a new one if necessary, with a reference to this one)