TypoScript random string generation

Is it possible to automatically generate a mixed string of numbers and TypoScript letters, for example. 12A54 or something like that?

+4
source share
3 answers

As already mentioned, there is no such function in Typoscript, so the preferred method should use some function of the PHP script, as suggested in other answers.

However, there is a cheat , and that will be using MySQL. Of course, this solution is only if you absolutely cannot (for the reason that I really can’t think of it) write a piece of custom PHP. Take it more as an academic answer than a practical one.

 temp.random = CONTENT temp.random { table = tt_content select { pidInList = 1 recursive = 99 max = 1 selectFields = SUBSTRING(MD5(RAND()) FROM 1 FOR 6) AS random_string } renderObj = TEXT renderObj { field = random_string case = upper } } 

NOTES:

  • pidInList must point to an existing page.
  • The MySQL command is just an example, since a string will never contain the letters GZ. I am sure it is possible to come up with a better string generated by MySQL.
+5
source

I would prefer that userFunc on php include a script. For example, you can pass parameters to a user-defined function.

TypoScript:

 includeLibs.generateInvoiceNo= fileadmin/scripts/generateInvoiceNo.php temp.invoiceNo = USER temp.invoiceNo { userFunc =user_generateInvoiceNo->main } 

PHP:
fileadmin / scripts / generateInvoiceNo.php

 <? class user_generateInvoiceNo { var $cObj;// The backReference to the mother cObj object set at call time /** * Call it from a USER cObject with 'userFunc = user_generateInvoiceNo->main' */ function main($content,$conf){ $length = 6; $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $number=substr(str_shuffle($chars),0,$length); return $number; } } ?> 

Loans:

+4
source

Fixing TYPO3 sources for such simple tasks is the wrong idea. After the next source update, you will lose your changes.

Instead, it's better to include a simple PHP script where you can do what you need to check TSREF

+3
source

Source: https://habr.com/ru/post/1440758/


All Articles