I am new to extbase(MVC) Framework , How can we get typoscript values in our extension :
Eg : suppose if i have some typoscript values like:
plugin.tx_some-extname.somevlaueX = XXXX
plugin.tx_some-extname.somevlaueY = yyyy
plugin.tx_some-extname.somevlaueZ = zzzz
how will i get these values in a specific action of our controller .I hope this makes sense ??
Declare values in the settings scope (in the setup field) ie:
plugin.tx_some-extname.settings {
myXsetting = XXXX
}
So the all settings will be accesible in your plugin in $this->settings (as array) :
$valX = $this->settings['myXsetting'];
In TYPO3-7.6 + the whole TypoScript for an extension can be retrieved with
$typoScript = $this->configurationManager->getConfiguration( $this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK);
where for the 1st parameter exist 3 different options:
$this->configurationManager::CONFIGURATION_TYPE_SETTINGS
$this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK
$this->configurationManager::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
optional for the function $this->configurationManager->getConfiguration() the extension-key can be given as 2nd parameter and the plugin-name as 3rd parameter. So the whole command looks like this:
$typoScript = $this->configurationManager->getConfiguration( $this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK, $extensionKey, $pluginName );
Consider that the static template has to be included in the backend-template to return the desired output.
ConfigurationManager is an instance of
TYPO3\CMS\Extbase\Configuration\ConfigurationManager
Related
I try to redirect a link which is coming, but before part of the link should be replaced.
tmp.getSlug = TEXT
tmp.getSlug.data = getIndpEnv : TYPO3_REQUEST_URL
tmp.getSlug.replacement {
10 {
search = myLinkPart
replace = myNewLinkPart
}
}
config.additionalHeaders.10 {
header = Location: {tmp.getSlug}
}
So from: www.myUrl.de/test/myLinkPart/test2/
To: www.myUrl.de/test/myNewLinkPart/test2/
It must be inside Typoscript because of other conditions.
Does anybody has an idea?
you are mixing different objects in a non functional way.
First you define tmp.getSlug as a typoscript object. Then you try to use it as a data variable.
Additional everything beyond tmp. is not available at rendering time. (it just is available when the typoscript is scanned.)
If you want to use the evaluation of tmp.getSlug you need to assign it to a permanent object and then store it in a register so you can access it afterwards.
Additional you need a flexible object to compose the Location header, which by default just contains a string.
Either a text object where you can use data (which must be evaluated and stored in a register before) or a COA to compose the static and the dynamic string.
This might be a solution:
tmp.getSlug = TEXT
tmp.getSlug.data = getIndpEnv : TYPO3_REQUEST_URL
tmp.getSlug.replacement {
10 {
search = myLinkPart
replace = myNewLinkPart
}
}
config.additionalHeaders.10 {
header.cObject = COA
header.cObject {
10 = TEXT
10.value = Location:
20 < tmp.getSlug
}
}
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.
Per default the search form contains the following inputs:
Instead of the two Inputs "Startdatum" and "Enddatum" i want a selectbox with a month option.
In
typo3conf\ext\cal\Resources\Private\Templates\v2\search_event.tmpl
there are only the post parameters start_day and end_date for the search.
How to realize am month selextbox if i only can select and post a month value ?
Must i make changes here?
typo3conf\ext\cal\Classes\View\SearchViews.php
Can i realize this with an own cal extend extension?
Given you use content element of type plugin with view set to 'list' and add your own form select for month, which generates requests with parameter like
?tx_cal_controller[month]=08
then you can manipulate list results with a typoscript condition to show only events from requested month of current year:
[globalVar = GP:tx_cal_controller|month >0]
plugin.tx_cal_controller.view.list.useCustomStarttime = 1
plugin.tx_cal_controller.view.list.useCustomEndtime = 1
plugin.tx_cal_controller.view.list.customStarttimeRelativeToGetdate = 1
plugin.tx_cal_controller.view.list.customEndtimeRelativeToGetdate = 1
plugin.tx_cal_controller.view.list.starttime = monthstart
plugin.tx_cal_controller.view.list.endtime = monthend
[global]
To use your own category filter for list view, you need to adapt/extend class \TYPO3\CMS\Cal\Controller\Controller::initConfigs() to invoke a parameter like
?tx_cal_controller[category]=2
into global configuration like
/**
* Init configurations
* Change category mode in listview, if category given in GET params
* Used for category filter by selection
*/
public function initConfigs() {
parent::initConfigs();
if ($this->piVars['category'] && $this->conf ['view'] === 'list') {
$this->conf ['view.'] ['categoryMode'] = 4;
$this->conf ['view.'] ['category'] = $this->piVars['category'];
}
}
For a working filter of event owner I have no example.
I need to call typo3 plugin from other plugin's body and pass its result to template. This is pseudo-code that describes what I want to achieve doing this:
$data['###SOME_VARIABLE###'] = $someOtherPlugin->main();
$this->cObj->substituteMarkerArray($someTemplate, $data);
Is it possible?
Thanks!
It doenst work if you use the whole pi construct, e.g. for links, marker function etc, and the TSFE Data can be corrupted.
Dmitry said:
http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1'];
$conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1.'];
$cObj = t3lib_div::makeInstance('tslib_cObj');
$cObj->start(array(), '_NO_TABLE');
$conf['val'] = 1;
$content = $cObj->cObjGetSingle($cObjType, $conf); //calling the main method
You should use t3lib_div:makeInstance method.
There is a working example from TYPO3's "powermail" extension.
function getGeo() {
// use geo ip if loaded
if (t3lib_extMgm::isLoaded('geoip')) {
require_once( t3lib_extMgm::extPath('geoip').'/pi1/class.tx_geoip_pi1.php');
$this->media = t3lib_div::makeInstance('tx_geoip_pi1');
if ($this->conf['geoip.']['file']) { // only if file for geoip is set
$this->media->init($this->conf['geoip.']['file']); // Initialize the geoip Ext
$this->GEOinfos = $this->media->getGeoIP($this->ipOverride ? $this->ipOverride : t3lib_div::getIndpEnv('REMOTE_ADDR')); // get all the infos of current user ip
}
}
}
The answer of #mitchiru is nice and basically correct.
If you have created your outer extension with Kickstarter and you are using pi_base then there is already an instance of tslib_cObj and the whole construct becomes simpler:
// get type of inner extension, eg. USER or USER_INT
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1'];
// get configuration array of inner extension
$cObjConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1.'];
// add own parameters to configuration array if needed - otherwise skip this line
$cObjConf['myparam'] = 'myvalue';
// call main method of inner extension, using cObj of outer extension
$content = $this->cObj->cObjGetSingle($cObjType, $cObjConf);
Firstly, you have to include your plugin class, before using, or outside your class:
include_once(t3lib_extMgm::extPath('myext').'pi1/class.tx_myext_pi1.php');
Secondly in your code (in the main as example)
$res = tx_myext_pi1::myMethod();
This will work for sure (I've checked this): http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html.
Probably Fedir's answer is correct too but I didn't have a chance to try it.
Cheers!
I want to output a string to the rendered HTML by using two fallbacks.
My typoscript is defined at the top level page (root page of my website) and is passed to all pages at lower levels.
Structure:
Homepage
Page at level 1
Page at level 2
Regular output of the file:
The string comes from a TemplaVoila field (Page / Edit / Extended / MyField): field_copyright_name
To output it to the desired point in the HTML output a templaVoila mapping exists (Type: Typoscript Object Path), named: lib.copyright_name
The following typoscript does the job:
lib.hint_copyright_name = COA
lib.hint_copyright_name.10 = TEXT
lib.hint_copyright_name.10 {
setCurrent.dataWrap = {field:field_copyright_name}
current = 1
}
This works for all pages at all levels where the field (in page properties) is not empty.
The first fallback:
If the field is empty (in properties of that page, e.g. at level 2) typoscript should get the value from the pages above (at level 1, and if it is empty too, it should get it from homepage). No clue how to do it. Can you help?
The second fallback
If the first fallback still returns an empty string (because the field was empty at all levels) it should do a fallback to a default value "Copyright by me".
To enable this fallback without "first fallback" is easy:
switchdefault_copyright_name = TEXT
switchdefault_copyright_name {
setCurrent.dataWrap = {field:field_copyright_name}
current = 1
override = "Copyright by me"
override.if.isFalse.field = field_copyright_name
}
lib.hint_copyright_name = COA
lib.hint_copyright_name.10 < switchdefault_copyright_name
But how to integrate the "first fallback"?
EDIT:
I tried:
setCurrent.data = {levelfield:-1, field_copyright_name, slide}
or
setCurrent.data = levelfield:-1, field_copyright_name, slide
or
setCurrent.dataWrap = {levelfield:-1, field_copyright_name, slide}
or
setCurrent.dataWrap = levelfield:-1, field_copyright_name, slide
but without success - no output.
Just found this : http://lists.typo3.org/pipermail/typo3-english/2006-October/032764.html
It's supposed to make youre slide thing to work.
Just set : Installation > all configuration > addRootLineFields
Didn't tried it, but seems like the solution