Feature #16180
closed
Added by Jean-Baptiste Rio over 18 years ago.
Updated over 11 years ago.
Description
A little patch to offer random value on listNum with the keyword 'rand' :
File class.tslib_content.php - Line 3347 and next
function listNum($content,$listNum,$char) {
$char = $char ? $char : ',';
if (t3lib_div::testInt($char)) {
$char = chr($char);
}
$temp = explode($char,$content);
$last = ''.(count($temp)-1);
+ if ($listNum = 'rand') $listNum = rand(count($temp));
$index=$this->calc(eregi_replace('last',$last,$listNum));
return $temp[$index];
}
(issue imported from #M3557)
Sorry a error when i key in. You have to read :
+ if ($listNum == 'rand') $listNum = rand(0,count($temp)-1);
What has to be done to get this feature into core?
I'm using something like this with a XCLASS but it would be nice to see this in core.
Frans
I agree this would be cool to have in core. I needed similar functionality and am now using an XCLASS as suggested by Frans.
bump
Would definitely be a cool feature!
that would be a great feature.
the code above doesen't work anymore with php5.3 and typo3 4.4 it should read:
+ if ($listNum === 'rand') $listNum = rand(0,count($temp)-1);
because of:
if(0 == 'anystring') //returns TRUE
see:
http://bugs.php.net/44999
Is Peter Niederlag still taking care of this issue? If not I could take care for a patch and make an RFC.
I would say: Just do it! :-)
- Category deleted (
Communication)
- Target version deleted (
0)
- PHP Version deleted (
5)
Patch set 5 of change I55efef8ed714eaa1545f9f179e18260661407de7 has been pushed to the review server.
It is available at http://review.typo3.org/2538
Use the following TS to test-drive the patch from Gerrit:
- Create a page and set it's subtitle field to someting comma-separated like "foo,bar,baz"
- Add a TS template record on that page with the lines below (adapt if your PAGE object is not "page")
- Clear all caches and test-drive that page in the frontend
Expected behaviour after applying the changes from Gerrit:
The subtitle field changes upon every reload
Typoscript code for testing:
page.5 = COA_INT
page.5 {
10 = TEXT
10 {
field = subtitle
stdWrap.listNum = rand
}
}
- Status changed from Accepted to Resolved
- % Done changed from 0 to 100
- Target version set to 1281
- Status changed from Resolved to Closed
- Target version deleted (
1281)
Also available in: Atom
PDF