What am I doing wrong? Block needs to be put into "Edit Mode" before updating dynamic content
Permalink
I have a block which I am trying to create dynamic content in.
Every time the page loads I am selecting another image and attempting to display this.
In a normal PHP file this would work as I load a random file each time, I had thought that the code below was loaded on each instance of the block view? but unless I go in and edit the content and press Update nothing changes.
I have no cache turned on(cleared also now) but am unable to get a different image to load?
can anyone point out any tips or pointer on how I can achieve this?
[I have tried running the random code on render/on_page_view/view from within the controller but none seem to do what I want ]
Do I need to move the calculations away from the view and back into the controller?
Every time the page loads I am selecting another image and attempting to display this.
In a normal PHP file this would work as I load a random file each time, I had thought that the code below was loaded on each instance of the block view? but unless I go in and edit the content and press Update nothing changes.
I have no cache turned on(cleared also now) but am unable to get a different image to load?
can anyone point out any tips or pointer on how I can achieve this?
[I have tried running the random code on render/on_page_view/view from within the controller but none seem to do what I want ]
Do I need to move the calculations away from the view and back into the controller?
<?php $array = array(1,4,5); //image positions in the db I would like to check shuffle($array); $rand = rand(1,3)-1;//index of array $imageNo = $array[$rand]; //should this be done in the controller? $found=false; foreach($array as $a=>$v){ if (!empty(${'field_'.$v.'_image'})){ $imageNo = $v; } } ?> <?php for($i=0;$i<3;$i++){
Viewing 15 lines of 26 lines. View entire code block.
Not saying that is why you're getting the same image, but rand has caused me problems in the past - if I understand what you are trying to achieve correctly you don't need to use rand.
Hope that helps