I am currently developing my own TYPO3 extension (in v 9.5.11) and I would like to make some settings of my extension customisable. When I go to Admin Tools-->Settings-->Extension Configuration-->Configure Extensions, I can already change those settings.
However in earlier versions of TYPO3 (e.g. v7) it was possible to also make an extension configurable through Admin Tools-->Extensions-->"clicking the settings wheel of the desired extension" (see picture).
Where do I implement said function?
You simply define your desired settings in the file ext_conf_template.txt which needs to be stored in the root level of your extension.
The official TYPO3 documentation contains detailed instructions.
Like Michael said, you need to put all settings into the ext_conf_template.txt
Here is an example of my extension "slug" wich you can also find on Github or in the TYPO3 repository. It contains some special fields and even translations.
# Settings
###########################
# cat=defaults; type=options[10,20,30,40,50,60,70,80,90,100,150,200,300,400,500]; label=LLL:EXT:slug/Resources/Private/Language/locallang_be.xlf:default.maxentries
defaultMaxEntries = 20
# cat=defaults; type=options[crdate,tstamp,title,slug,sys_language_uid,is_siteroot,doktype]; label=LLL:EXT:slug/Resources/Private/Language/locallang_be.xlf:default.orderby
defaultOrderBy = crdate
# cat=defaults; type=options[DESC,ASC]; label=LLL:EXT:slug/Resources/Private/Language/locallang_be.xlf:default.order
defaultOrder = DESC
# cat=defaults; type=boolean; label=LLL:EXT:slug/Resources/Private/Language/locallang_be.xlf:default.recordInfoEnabled
recordInfoEnabled = 1
# cat=tree; type=boolean; label=LLL:EXT:slug/Resources/Private/Language/locallang_be.xlf:tree.enabled
treeEnabled = 1
# cat=tree; type=options[1,2,3,4,5,6,7,8,9,10]; label=LLL:EXT:slug/Resources/Private/Language/locallang_be.xlf:tree.depth
treeDefaultDepth = 3
# cat=tree; type=string; label=LLL:EXT:slug/Resources/Private/Language/locallang_be.xlf:tree.root
treeDefaultRoot =
# cat=custom records; type=boolean; label=LLL:EXT:slug/Resources/Private/Language/locallang_be.xlf:record.enabled
recordEnabled = 0
# cat=custom records; type=options[10,20,30,40,50,60,70,80,90,100,150,200,300,400,500]; label=LLL:EXT:slug/Resources/Private/Language/locallang_be.xlf:record.maxentries
recordMaxEntries = 10
# cat=custom records; type=options[crdate,title,path_segment,sys_language_uid]; label=LLL:EXT:slug/Resources/Private/Language/locallang_be.xlf:record.orderby
recordOrderBy = crdate
# cat=custom records; type=options[DESC,ASC]; label=LLL:EXT:slug/Resources/Private/Language/locallang_be.xlf:record.order
recordOrder = DESC
And here is how I use the settigs in any Controller I want:
<?php
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
class ExtensionController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
public function __construct() {
$this->backendConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('slug');
}
public function myRandomFunction(){
$variable = $this->backendConfiguration['recordMaxEntries'];
}
}
This is how it looks:
Related
I want to set the Sitename in Constants by default, so I can use this settings.variable in my Fluidtemplate.
I found in another post here on stackoverflow:
DB:sys_template|1|title
GLOBAL:TYPO3_CONF_VARS|SYS|sitename
But if I use this in my constants.ts like this:
# cat=plugin.tx_rmnavigation/01_NaviSettings/a; type=string; label=testing sitetitle
testsitetitle = DB:sys_template|1|title
OR
# cat=plugin.tx_rmnavigation/01_NaviSettings/a; type=string; label=testing sitetitle
testsitetitle = GLOBAL:TYPO3_CONF_VARS|SYS|sitename
AND in my setup.ts:
testsitetitle = {$plugin.tx_rmnavigation.settings.testsitetitle}
I get only the text not the value of the "variable" see this picture Constant Editor...
How can I use the Sitename in Constants as a defaultvalue?
Edit
I forgot to say, perhaps it's important for this issue, I try this here in both files:
plugin.tx_rmnavigation {
settings {
..
}
}
You have to assign your constant to a content object's data property (see https://docs.typo3.org/typo3cms/TyposcriptReference/8.7/ContentObjects/Index.html and https://docs.typo3.org/typo3cms/TyposcriptReference/8.7/Functions/Stdwrap/Index.html#data) to get it resolved:
testsitetitle = TEXT
testsitetitle.data = {$plugin.tx_rmnavigation.settings.testsitetitle}
And I would prefer your second variant for the constant definition because it uses the value from the current template record:
# cat=plugin.tx_rmnavigation/01_NaviSettings/a; type=string; label=testing sitetitle
testsitetitle = GLOBAL:TYPO3_CONF_VARS|SYS|sitename
But the first one should also work if you use colons instead of pipes:
testsitetitle = DB:sys_template:1:title
If you have a multi domain page the query to DB:sys_template:1:sitetitle might not work, as the 1 is the UID, not the PID of the root node of your template. But TSFE to the rescue!
In the context of your page call, the TSFE already has the sitetitle from the backend template loaded.
If you for example want to output a og:site_name, you can access the value by using:
og:site_name = TEXT
og:site_name {
data = TSFE:tmpl|sitetitle
attribute = property
}
This way no additional database queries are needed and it will work on multi domain, multi root node pages.
Thanks for your suggestions. I found a solution with your infos.
Honestly I think this doesn't works in Constants, because the both methods are readonly.
So I found a working solution for my Issue: I need that Variable only for read in my Templates, so I create a new Typoscript File libs.ts and included this with:
# Include Libraries
<INCLUDE_TYPOSCRIPT: source="FILE: EXT:rm_navigation/Resources/Private/TypoScript/libs.ts">
in the /Configuration/TypoScript/setup.ts File.
The content of libs.ts is:
TSFE-Syntax
lib.sitename = TEXT
lib.sitename.data = GLOBAL:TYPO3_CONF_VARS|SYS|sitename
OR
DB-Syntax
lib.sitename = TEXT
lib.sitename.data = DB:sys_template:1:sitetitle
works both. I read that you use the colon-syntax for DB usage and the pipe-syntax for Global Variables.
To get this to Fluid use this Code:
<f:cObject typoscriptObjectPath="lib.sitename" />
I hope it helps Others who also has this Issue.
I have a multilingual site built with TYPO3 V7.6.18. It uses a slogan which should remain editable but different for three languages. This is a variable that is hard-coded in the Fluid templates.
For variables of this kind I use a file Configuration/TypoScript/constants.ts where I define the variable that can be edited (WEB -> Template -> Constant Editor) and used:
#---------------------------------------------------------------------
# constants.ts
#---------------------------------------------------------------------
# customsubcategory=general=General Setup
myextension.configuration {
general {
# cat=myextension/general/05; type=string; label=Website Slogan.
slogan= website slogan in main language
}
}
[globalVar = GP:L=1]
myextension.configuration.general.slogan = website slogan in second language
[end]
[globalVar = GP:L=2]
myextension.configuration.general.slogan = website slogan in third language
[end]
I then bind the variable in Configuration/TypoScript/setup.ts for use:
#---------------------------------------------------------------------
# setup.ts
#---------------------------------------------------------------------
page = PAGE
page {
# Page Main template
10 = FLUIDTEMPLATE
10 {
variables {
# slogan
slogan = TEXT
slogan.value = {$myextension.configuration.general.slogan}
}
}
}
This code works, but only the slogan in the main language is editable ...
Any solution to make the slogans editable in the other two languages?
Three possibilities suggest themselves, two of which were mentioned by Mathias and Riccardo. I‘ll add a third one an list pros and cons of them.
So, firstly the third possibility which is to create a content element (preferably of type header) and create a TypoScript constant holding its uid.
# cat=myextension/general/05; type=int; label=Slogan CE UID
myextension.configuration.general.sloganUid =
Then fetch this content element‘s header in your fluid variable:
page.10.variables.slogan = CONTENT
page.10.variables.slogan {
select.uidInList = {$myextension.configuration.general.sloganUid}
table = tt_content
renderObj = TEXT
renderObj.field = header
}
Create a sysfolder, create a content element of type header and plumb its uid in your constant. Maybe you‘ll have to add some more stuff to .select to make it work - I‘m always unsure that.
Now pros and cons:
Three constants, as suggested by Mathias:
pro: Closed to what you did, easy, little code, no file access needed for changes
con: need to add another constant to constants and setup for each additional language
locallang.xlf:
pro: That‘s where you expect translations (in code), easy to add translations, can go to VCS
con: Needs file access to change
Content element:
pro: Admin can grant access to editors (if they want), easiest to add translations
con: adds DB queries (but normally cached), easy to screw up from BE
I'd recommend to use language identifiers for the constants instead:
myextension.configuration {
general {
slogan {
# cat=myextension/general/05; type=string; label=Website Slogan in default language.
default = website slogan in main language
# cat=myextension/general/06; type=string; label=Website Slogan in second language.
second = website slogan in second language
# cat=myextension/general/07; type=string; label=Website Slogan in third language.
third = website slogan in third language
}
}
}
Then move the condition to the setup:
page = PAGE
page {
# Page Main template
10 = FLUIDTEMPLATE
10 {
variables {
# slogan
slogan = TEXT
slogan.value = {$myextension.configuration.general.slogan.default}
}
}
}
[globalVar = GP:L=1]
page.10.variables.slogan.value = {$myextension.configuration.general.slogan.second}
[end]
[globalVar = GP:L=2]
page.10.variables.slogan.value = {$myextension.configuration.general.slogan.third}
[end]
I want to form file path.
In "Constant" field:
const.siteName = site
templates = fileadmin/templates/{$const.siteName}/
When i look in typoscript object browser:
[siteName] = site
[templates] = fileadmin/templates/{$const.siteName}/
Is it possible to achieve this:
[templates] = fileadmin/templates/site/
using const.siteName?
If yes, how?
=========================================================================
EDIT:
What i am tying to do is next:
In my extension configuration
const.siteName = foo
const.templates = fileadmin/templates/($const.siteName)/
const.path.extensions = ($const.templates)/ext/
I include my extension in typoscript template. In my extension setup i include setup for plugin like this:
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:foo/Configuration/TypoScript/Plugin/formhandler.ts">
In Configuration/TypoScript/Plugin/formhandler.ts:
plugin.Tx_Formhandler {
/* snip */
settings.predef.member {
templateFile.value = {$const.path.extensions}formhandler/member/step-1.html // doesn't work
//templateFile.value = fileadmin/templates/foo/ext/formhandler/member/step-1.html // works
}
/* snip */
}
For me, this example works perfect:
Constants:
const.test = foo
const.test2 = {$const.test}/bar
Setup:
page = PAGE
page.10 = TEXT
page.10.value = {$const.test}
page.10.wrap = <p>|</p>
page.20 = TEXT
page.20.value = {$const.test2}
page.20.wrap = <p>|</p>
Output in Browser:
foo
foo/bar
Tested with TYPO3 4.5 and 8.3
Have a look at the TYPO3 NG/ML/Forum:
https://forum.typo3.org/index.php?t=msg&th=212721&goto=740111&#msg_740111
there are a lot of hints how to use constants in typoscript:
you can reuse constants in constants definition, but only up to 10 levels deep.
you can use constants in conditions, but only in setup-part
short : NO
long: you can only use constants in your setup.
what you can do is:
CONSTANTS
const.siteName = site
const.templatePath = fileadmin/templates
SETUP:
myTemplate= {$const.templatePath}/{$const.siteName}
I have a nearly unconfigured flexform (only set the Switchable Controller Action to "list") which I wanted to configure via TypoScript, e.g. as such:
plugin.tx_news {
settings {
pluginType = news-list
limit = 999
orderBy = datetime
orderDirection = desc
startingpoint = {$pidNewsStorage}
detailPid = {$pidNewsDetail}
archiveRestriction = active
categories = 24
categoryConjunction = and
}
}
The TS is included in the page's setup, and the properties show up correctly in the TSOB.
Strangely, not all settings will work (the custom setting pluginType for use in fluid works, while detailPid doesn't). By "work", I mean override the empty settings in the flexform.
Some default settings I have set on the root page DO apply.
Where could I look?
You can also add here the fields which you want to override from typoscript
plugin.tx_news.settings.overrideFlexformSettingsIfEmpty = cropMaxCharacters,dateField,timeRestriction,orderBy,orderDirection,backPid,listPid,startingpoint,recursive,list.paginate.itemsPerPage,list.paginate.templatePath,templateLayout
Is it possible to auto generate a mixed string of digits and letters by TypoScript, e.g. 12A54 or something similar?
I'd prefer a userFunc to a php include script. For example, you can pass parameters to a user 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;
}
}
?>
Credits:
This php script
TYPO3 Wizard on userFunc
As already mentioned, there is no such functionality in Typoscript and so the preferred method is to use some simle PHP function as suggested in other answers.
However, there is a cheat and that would be to use MySQL. Mind you, that it's a solution only if you absolutely cannot (for a reason that I really cannot think of) write a piece of custom PHP. Take it rather 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 really just an example as the string would never contain letters G-Z. I'm sure it's possible to come up with a better string generated by MySQL.
Patching TYPO3 sources for such easy tasks is wrong idea. After the next source upgrade you'll lose your changes.
Instead it's better to include an easy PHP script where you can render what you need check TSREF