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!
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.
Or in includeJSFooter I have tried
includeJSFooter {
initJavascript = path/to/file/init.js
initJavascript.id = initJavascript
}
but It does not work and I do not see any option in the docs but maybe I have missing something.
This is not possible. For this kind of inclusion you need to use page.headerData or page.footerData.
See: https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Page/Index.html#headerdata
i know how i get the current URL with typoscript, but i dont know how i can parse this url into a variable so i can use and work with it.
temp.getUrl = TEXT
temp.getUrl.typolink {
parameter.data=TSFE:id
returnLast=url
}
This example returns me an url segment like 'This/is/just/a/test.html', so long – perfect!
Now i try to save this url into an Variable like
temp.getUrl = TEXT
temp.getUrl.typolink {
parameter.data=TSFE:id
returnLast=url
}
wiredMindsCompleteUrl < temp.getUrl
This results everytime just with 'TEXT' :( i kinda depressed.
Please help :)
The question is, where do you want to use it.
If you want to use it in different places in TypoScript you can f.e. render it into stdWrap.append / stdWrap.prepend of your links.
myMenu = HMENU
myMenu ...
myMenu.stdWrap.append < temp.getUrl
You could just put it into an Register:
page.1.LOAD_REGISTER
page.1.getUrl < temp.getUrl
and f.e. use your register in the tilte-Tag of an image:
lib.MyImage = IMAGE
lib.MyImage.file = ...
lib.MyImage.titleText.data = REGISTER:getUrl
lib.MyImage.tilteText.noTrimWrap = | makes no sense (IMHO:) ||
If you need it in your extension, just use it with cObjGetSingle.
plugin.tx_yourextension_pi1.getUrl < temp.getUrl
Inside your extension use it via
function main($content, $conf) {
$this->conf = $conf;
return $this->cObj->cObjGetSingle($this->conf['getUrl'], $this->conf['getUrl.'], 'getUrl');
}
Side note: use lib.getUrl instead of temp.getUrl, otherwise you can get in trouble with non-cached TypoScript parts.
I made module addition and in this made three fields amount1_c, amount2_c and total_amount_c to add the two numbers and display the result in the third field. I done coding in the logic looks here is my code
<?
$hook_version = 1;
$hook_array = Array();
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1,'calculate_field', 'custom/modules/cases/LogicHookMath.php','LogicHookMath', 'calculate_field');
?>
and made one more file logic hook math. here is my code for
<?php
class LogicHookMath {
function calculate_field(&$bean, $event, $arguments) {
$field1 = $bean->amount1_c;
$field2 = $bean->amount2_c;
$field3 = $field1 + $field2;
$bean->amount_total_c = $field3;
}
}
?>
but still i did not get any result. Please help me out for this.
The code looks correct.
Some common "mistakes" when custom logic hooks are not working:
Make sure, the custom logic hook has the correct name (LogicHookMath.php)
Make sure, that the $bean variable is prefixed with &, so the variable is passed as a reference
Make sure the logic_hooks.php and the LogicHookMath.php files are readable by the web server user
The entire custom directory should also be writeable for the web server user
If the above does not help, try logging the progress to the sugarcrm.log using $GLOBALS['log']->info( "Value 3: ". $field3); in the custom logic hook.
I've got this odd problem.
If I make a call on that function through amfphp service browser and give it a valid ID and leave the $num_images field blank amfphp will actually pass a blank string as the argument.
// if i call this function width just an ID
function getWorkers($id, $num_images = 100) {
...
// num_images will be set as ''
}
I can easily override using a check:
function getWorkers($id, $num_images = 100) {
if($num_images=='') $num_images = 100;
...
// num_images will now be really set as 100
}
Anyone experiencing the same with amfphp?
That's odd, I never got that from AMFPHP. If you don't have the latest version try updating your installation of AMFPHP. Also make sure Flash doesn't somehow pass an empty variable as the second variable.
(Copied from the comment.)