I'm using Typo3 9.5 and got some hardcoded variables within my fluid templates. I'm trying to make this variables depending on what language the page is viewed. Default value works fine. But making use of TypoScript like
[globalVar = GP:L = 1]
#whatever
[end]
for instance already throws an Error within the console either way and therefore does not override an variable. I think I've done this before in previous Typo3 versions. How do I achieve language depending variables and render it within my FLUID template?
You shouldn't be assigning your variables this way. The right way to handle this is to create XLF files that can be referenced with f:translate to translate a given key into any language as long as there's an XLF file for it.
This method is used and supported throughout TYPO3, not just in Fluid. Nearly all labelling options support LLL:... references where you can point to specific files.
You are encouraged to create an extension that can contain such files and then reference them with LLL:EXT... paths and/or use extensionName on f:translate in your Fluid templates if the extension is other than the one rendering your Fluid templates.
Related
For both "TypoScript constants" and "Extension Configuration" (as defined in ext_conf_template.txt) use a common syntax. They are documented here:
Constants (in "TypoScript Template Reference")
Extension Configuration (in "TYPO3 Explained")
An example:
# cat=basic; type=string; label=Some title
title =
Line 1 describes data type, category etc. of the variable.
Alternatively, we might have something like this:
tx_plugins.my_plugin {
# cat=basic; type=string; label=Some title
title =
}
Besides this rather simple example, there are some more things you can do with this.
Where TypoScript constants and Extension Configuration are stored and how they are used is completely different, but I am wondering if we just look at the syntax and the features you can use - is it the same?
e.g.
the available datatypes (boolean, integer etc.)
that you can't use multiline values
that you can use environment variables
how to access files
how to do localization
The reason I ask: To streamline the documentation and also I use this in my own extensions.
Short Answer
The syntax used for TS template constants and extension configuration is the same but there are some minor differences for the available types currently.
Deep Analysis
Extension Configuration
For TYPO3 CMS version 6 the extension manager and configuration was rewriten from scratch based on Extbase and using the FormEngine. Available types are:
int: integer values
int+: positive integer values only
integer: alias for int
color: color picker
wrap: wrap, lines are separated finally by | for the saved value
offset: offset field
options: select
boolean: checkbox
user: user function is used for rendering
small: small text field
string: text field
input: alias for string, only for backwards compatibility, many extensions depend on that
default: alias for string, only for backwards compatibility, many extensions depend on that
Source is available here: https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/core/Classes/ViewHelpers/Form/TypoScriptConstantsViewHelper.php#L36
TypoScript Template Constant Editor
On the other hand the TypoScript template constant editor was never rewriten to make use of the FormEngine and has it's own implementation. Here the following types are additionally available:
comment: a checkbox to switch a constant
files: file selection
Source is available here: https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php#L993
Other Questions
that you can't use multiline values
That's almost true for the TS constant editor but there is the wrap type to achieve a multiline like functionality. For the extension configuration there are the small and string types.
For the other questions I'm currently not aware of and have to investigate a little bit deeper first:
that you can use environment variables
how to access files
how to do localization
As Typoscript is a configuration it can be used in multiple ways. And TYPO3 uses it differntly. So you have to diferentiate.
Constants can be used only for frontend rendering. there they are a shortcut to use a given value in different places.
Or to easily configure something (extension) without knowledge of detailed setup. Therefore you have the Constant-Editor where you can define constants which got a special information/ comment. It's like the TCA, a help to build forms and automaticaly have some validators for data. as TS-constants only are strings which can be used in the setup you do not have real data types. it is just a configuration to have some validation in the Constant-Editor.
Aside from some recursive replacement (up to a level of 10) of constants in constants definition you have no further options to compute a value.
In Typoscript setup you have (meanwhile) stdWrap funtionality nearly everywhere.
But especially extensions don't evaluate it everywhere. so in some places you have an extension configuration in setup where you only can insert fixed strings. (like in the constants)
on the other hand:
how can an extension be configured (with TYPO3-tools)?
Aside from the Typoscript setup (where you can use the constants), which primarily is used for the frontend rendering (*) you have a global option to configure extensions with the extension manager.
This data is stored serialized in typo3conf/LocalConfiguration.php. since TYPO3 9 unserialized.
It can be accessed in frontend and backend and works globaly, while the frontend typoscript or TSconfig is dependend on the page (and user).
This brings us to the third part of configuration: TSconfig
We have page-TSconfig and user-TSconfig. In pages, be_users and be_groups you can define a configuration with typoscript syntax. This can be enhanced with 'global' PHP code of extensions which inject further configuration in ext_localconf.php and ext_tables.php (or the successors in /Configuration/TCA/ and /Configuration/TCA/Overrides/)
(*) some extensions evaluate the frontend typoscript for configuration of backend modules or plugins-options
The common way to write the TypoScript is in Configuration/TypoScript/setup.txt.
But there also two other way to write TS. One with ext_typoscript_setup.txt and other with ExtensionManagementUtility::addTypoScriptSetup().
Can someone explain me what the difference is and when should i use which one?
Theoretically the usage of ext_typoscript_setup.txt files has been deprecated. Theoretically because it has never really been removed from the core.
ext_typoscript_setup.txt and ExtensionManagementUtility::addTypoScriptSetup() do quite the same thing as those will always load the given TypoScript. However the problem is that sometimes people have a hard time overriding those default code. To make it even more complicated there is the select field Static Template Files from TYPO3 Extensions inside the sys_template record which can influence the order.
As a solution (or at least how I handle it):
Always use the way of having TS in Configuration/TypoScript/... and let the integrator decide how and in which order it is included. Some people include TypoScript within their SitePackage, some in sys_template record, ...
However I also use ext_typoscript_setup.txt in rare case if some TS must be available and which won't be changed by an integrator.
I have some data (logins) I want to be ignored from git in my custom TYPO3 extension code.
As AdditionalConfiguration.php is already ignored in my case, it seems a good place to store such data.
It normally contains Data like
$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname']
Now would it make sense to make something like custom globals? Does that exist?
$GLOBALS['CUSTOM_CONF_VARS']['MYEXT']['username']
Should and can I do that or not?
I think you can use your own globals. But I would consider using your own globals as bad programming style.
If you have installation specific data the right way to store the data depends on the kind of data and where you need it:
everything for the Frondend should be stored in typoscript. This can be in a file from a site-extension or in the database (template record)
for BE you could use Page- or User-TSconfig. here you also can use a file from a site-extension or database records (pages/be_user)
if you have FE and BE or anything alse (e.g. scheduler jobs) you can use extension specific global data, you can set in the extension manager. -> docs.
Instead of saving configuration in $GLOBALS try use typoscript. Will be much easier to keep and maintain it.
I'm building a proper extension for the management of real estate, I would like to use the added "Image Metadata" field "Show in list view" as the extension tx_news does.
I can build this option in exactly as tx_news does but in case the site instalation uses both extensions, does this cause a conflict ? ( I'd use the same field name showinpreview )
Should I use a different field name to avoid trouble?
( I plan to use this feature in the exact same fashion, so I can easily share the use of the field in the "sys_file_reference" table ... if there was no other conflict there could be the case that an image was used in both extensions and the selection would be determined by one of the two extensions for both or do I misunderstand something here... )
anybody did experiments with this and can avoid me the trouble ?
I never had this use case but both ways are possible.
- use the same field: less code needed but your extension depends on news
- new field: also fine
You can use the same field as there also is a field which identifies the table the record belongs to.
Be sure to stay in sync with tx_news. either by a dependency, which might be a great overhead if you don't use tx_news otherwise, or with the same declaration as in tx_news, this can conflict if tx_news changes declaration unnoticed.
You have to declare your own access which will be independent as you use other namespace and context.
I'm new to the fedext-universe. By now, I've created a set of content elements, and they work fine.
There is one drawback though: One set of content elements has some fields in common, and these fields are rather complicated. Usually, I'd move their definition to a partial, but that isn't possible in flux forms. The beginners guide states
Flux templates can use Layouts and
Partials - but a Flux form cannot
be split into Partial templates.
Is there any way to avoid redefining these fields over and over again? Among other things, I've tried to use the <vhs:render.inline> viewhelper along with a custom viewhelper, returning the fluid-definition of the fields, but I can't get that to work.
Flux 7.0 will bring the option to place fields and sheets into Partial templates - if you are currently in a development project, I recommend trying it out from the development branches on Github:
https://github.com/FluidTYPO3/flux/tree/development
Flux 7.0 also will bring the option to create PHP classes which for example create ready-made sheets with a bunch of fields - such a class would be ideal to reuse, simply requiring one PHP class and one Fluid ViewHelper. Such an approach would be more efficient when your forms are rendered, but of course is much more technically demanding than a Partial template.
EDIT: though not yet documented, creating custom sheets involves two simple steps: 1) create a subclass of FluidTYPO3\Flux\Form\Container\Sheet and a subclass of FluidTYPO3\Flux\ViewHelpers\Form\SheetViewHelper - then include your namespace in the template, use your own ViewHelper instead of a flux:form.sheet (and add additional fields if you need them) and then inside the Sheet object, use the $this->createField() method from within object initialization, to automatically add any number of fields with predefined names, labels etc.