Hi
I wish to output a random global content block to the screen. I searched and found a few posts but cannot get anything to work.
Ideally I don't want all the GCB to output just those that I append with random_ for example {global_content name='random_offer1'}
I found this post http://forum.cmsmadesimple.org/viewtopi ... random_gcb who was using a tag called {random_gcb} but it appears to be a user defined tag and I cannot find anything about the tag.
Any ideas?
All help greatly appreciated.
output a random GCB
Re: output a random GCB
Did you check the forge?
http://dev.cmsmadesimple.org/projects/randomblob
Although this is marked as stale, it is probably because there is no need for additions. I had a look at the code and it looks like exactly what you need.
You might need to update the tag slightly to work with the latest CMSMS but it's definitely a step in the right direction.
Just place it in your plugins folder and see if it appears fine in your tags list (Extensions > Tags), if so it should be working and ready to use.
Cheers
MrEnigma
http://dev.cmsmadesimple.org/projects/randomblob
Although this is marked as stale, it is probably because there is no need for additions. I had a look at the code and it looks like exactly what you need.
You might need to update the tag slightly to work with the latest CMSMS but it's definitely a step in the right direction.
Just place it in your plugins folder and see if it appears fine in your tags list (Extensions > Tags), if so it should be working and ready to use.
Cheers
MrEnigma
~ Life is like water, every movement you make changes the way it flows ~
Re: output a random GCB
Hi and thanks for that.
I did check the forge and there are a few random type functions in there. I did installed the random_blob function but I cannot get it to work - it breaks the template.
I'm not good enough with the code to make it work with the latest CMSMS 1.11 series.
I did check the forge and there are a few random type functions in there. I did installed the random_blob function but I cannot get it to work - it breaks the template.
I'm not good enough with the code to make it work with the latest CMSMS 1.11 series.
Re: output a random GCB
just in case this is a quick job, here the code from the function. Is there a quick way to get this to work with the lastest CMSMS 1.11.2.1?
This is now 6 years old so its not surprising it doesn't work.
This is now 6 years old so its not surprising it doesn't work.
Code: Select all
function smarty_cms_function_random_blob($params, &$smarty) {
$blobs = HtmlBlobOperations::LoadHtmlBlobs();
if (!isset($params['prefix'])) {
return "Random Blob Error: no prefix defined";
} else {
$random_blobs = array();
foreach ($blobs as $one) {
if (preg_match("/^".$params['prefix']."/", $one->name)) {
$random_blobs[] = $one;
}
}
srand((float)microtime() * 1000000);
shuffle($random_blobs);
return $random_blobs[0]->content;
}
}
Re: output a random GCB
Try replacing:
With:
The rest looks up-to-date...
Cheers
MrEnigma
Code: Select all
$blobs = HtmlBlobOperations::LoadHtmlBlobs();
Code: Select all
$blobs =& cmsms()->GetGlobalContentOperations()->LoadHtmlBlobs();
Cheers
MrEnigma
~ Life is like water, every movement you make changes the way it flows ~