How can I replace custom tags with strings from an xlf file in TYPO3 - typo3

I'm trying to use the TYPO3 tags function to get strings from an xlf file. If I hard code the reference to the string I want, it returns successfully, but I need to know how to get it to return the appropriate string based on the tag content.
For example, this works:
HTML:
<var>myVar</var>
Typoscript:
lib.parseFunc_myExt{
tags {
var = TEXT
var{
value = {LLL:path/to/locallang.xlf:var.myVar}
insertData = 1
}
}
}
I need a method to take the content of the <var> tag and use it in place of myVar in the value.

Related

Retrieve content element field from within a plugin template?

I am modifying the template of a plugin, and I want to retrieve a field from the content element.
Using f:debug I see the only data available is from the plugin itself, and none from the content element.
Is there any way I can perhaps insert the field I need in the plugin settings?
eg. something like:
plugin.tx_plugin.settings {
contentUid = TEXT
contentUid.field = uid
}
The best way I can think of to do this is with a custom ViewHelper. Something like:
namespace MyVendor\MyExtension\ViewHelpers;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
class ContentUidViewHelper extends AbstractViewHelper
{
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
return $configurationManager->getContentObject()->data['uid'];
}
}
In your Fluid template:
<mynamespace:contentUid />
This will get the uid of the content element, but you can get any field this way. Just change the key of the data array to the field you need.
In the corresponding method (like the listAction or showAction) of the controller you can get the data of the content element in the following way:
$contentObject = $this->configurationManager->getContentObject();
$this->view->assign('contentObjectData', $contentObject->data);
As far as I know, you can't get to that data using typoscript, but I've never needed it anyway since I've been using the above code in the controller.
settings do not have stdWrap-type per default, but only string. So you can not use cObjects as values.
For one (or a few) settings, you could do the stdWrap-processing in your method/class yourself:
$settingsAsTypoScriptArray = $this->objectManager->get(TypoScriptService::class)->convertPlainArrayToTypoScriptArray($this->settings);
$contentObj = $this->configurationManager->getContentObject();
if ($contentObj === null) {
$contentObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
}
// now override the values in the settings array with the processed value
$contentUid = (int)$contentObj->stdWrap($settingsAsTypoScriptArray['contentUid'], $settingsAsTypoScriptArray['contentUid.']);
If you wanna have many settings to be stdWraped, have a look into EXT:news. Georg implemented an interesting concept via useStdWrap configuration.

look_down that checks (inside HTML) content

With HTML::TreeBuilder, using command $root->look_down(_tag => 'a') I get first anchor.
(1) How can I find last anchor?
Additionally, how can I check for inside content of the tag, to check if it does or does not contain some string inside of it? So for example,
(2) how can I find an anchor that contains "Hallo" or "hallo" in inside HTML?
(3) how can I find an anchor that DOES NOT contain "Hallo" or "hallo" in inside HTML?
The look_down() function returns a list of all <a> tags found, so simply access to last element of it using an index, like:
my $last_a_tag = ($root->look_down(_tag => 'a'))[-1]
To search into its text, use content_list() function, that returns a list with all child text elements. Then use a map() function to check if it contains or not any text, like:
map { m/[Hh]allo/ } $last_a_tag->content_list;

Typo3: Constant as Page UID

I have a list of constants assigned to various page IDs (e.g. myConstant = 22). Now I'd love to replace the following link
<f:link.page pageUid="22" >Link</f:link.page>
with something like
<f:link.page pageUid="{myConstant}" >Link</f:link.page>
I haven't been able to find the right syntax to do so. Any help?
i think you can't access the constants directly but you can use the constants in the ts-setup.
with plugin.tx_myplugin.settings.myPid = {$myConstant} in the ts-setup you can access the pid in your plugin with {settings.myPid}
if you're not using a plugin but a TS FluidTemplate you can assign it them like this:
page = PAGE
page {
10 = FLUIDTEMPLATE
10 {
file = fileadmin/templates/Home.html
variables {
pidList {
myConstant = {$myConstant}
myConstant2 = {$myConstant2}
}
}
}
}
<f:link.page pageUid="{pidList.myConstant}" >Link</f:link.page>
If you are using a FLUIDTEMPLATE typoscript-Object, you can do it as follows in TypoScript:
lib.output = FLUIDTEMPLATE
lib.output {
# ...
variables {
myPageID = {$myConstant}
}
# ...
}
In the fluid-template you can use the variables like you want:
<f:link.page pageUid="{myPageID}" >Link</f:link.page>
In case the template is rendered by an extension in a controller action, you can assign the value to a setting of your plugin: plugin.tx_<extkey>[_pi1].settings.myPageID = {$myConstant}. Then you can use it in the fluid template like this:
<f:link.page pageUid="{settings.myPageID}">Link</f:link.page>
In any case, you can assign that value to some TypoScript Object and read that in your template by either using the f:cObject ViewHelper or the v:var.typoscript ViewHelper from the extension vhs.
I tried something like that in t3 7.6 If you want to use a ts constant (defined in ts-constants field as oneConst) somewhere in your page fluid template you must do somthing like this:
page.10 = FLUIDTEMPLATE
page.10 {
variables{
const_one=TEXT
const_one.value={$oneConst}
}
}
}
Without the TEXT definition you will not get the value. Access it in your template:
{const_one}
Hint: i was not able to organize const in an array. Like
const{
one=TEXT
one.value={..}
}

TYPO3: How can I access property of objects in a partial or section?

I have an object defined in TypoScript
page.10 {
variables {
myObject = COA
myObject{
1 = TEXT
1.value = yome Text
2 = TEXT
2.value = 42
}
}
}
and I need the data of the myObject in a partial
<f:render partial="myPartial" arguments="{content:myObject}" />
that looks like
<section id="myPartial">
<h2>{content.1}</h2>
<p>{content.2}</p>
</section>
Although the content is there ( because {content} will display all the properties) I cannot access it and h2 and p will be empty...
What should I do to fill h2 and p with the content of myObject?
That is not possible. TypoScript only returns text strings at the moment, not arrays. Thus the variable myObject contains the whole concatenated string of the COA, thus yome Text42.
Note that COA means Content Object Array, but the whole COA is one single object that is returned as one string.
Alternative: use the VHS extension's v:var.typoscript ViewHelper:
{namespace v=Tx_Vhs_ViewHelpers}
{v:var.typoscript(path: 'page.10.variables.myObject') -> v:var.set(name: 'myObject')}
After which you can access {myObject.1} etc. in your template. Note that the so-called "chained" usage of v:var.set is optional, but will make it easier to access your variables using an intermediate template variable instead of more expensive calls to retrieve the value completely in multiple locations. The other way:
{v:var.typoscript(path: 'page.10.variables.myObject.1')}
{v:var.typoscript(path: 'page.10.variables.myObject.2')}
etc.
VHS extension on TER: http://typo3.org/extensions/repository/view/vhs

The concept of an object variable in typoscript

In my typoscript 20.special.value and 10.value.typolink.parameter have the same value, which is a page id. I use this value to build a heading and a menu of its subpages within the same COA object. I would like to be able to re-use this value.
How can I call a object property in typoscript?
Here's what I have tried:
10 = HTML
10 {
value.typolink {
parameter = {$temp.LANDINGPAGEMENU.20.special.value}
}
}
UPDATE:
I am re-utilizing my COA object in different parts of the site, and changing only the special.value, so to display a menu I have:
temp.LANDINGPAGEMENU.10.value.typolink.parameter = 2427
temp.LANDINGPAGEMENU.20.special.value = 2427
temp.COLUMN_NOTSURE < temp.LANDINGPAGEMENU
I am after a cleaner way of handling the
temp.LANDINGPAGEMENU.10.value.typolink.parameter = 2427
temp.LANDINGPAGEMENU.20.special.value = 2427
Full LANDINGPAGEMENU typoscript code is http://pastebin.com/p9kPuZEe
Use the constants but not in a way you tried. You have to define the constant first.
Constants: my_constant = 2427
Setup: parameter = {$my_constant}
...OR...
Assign one of the values by reference using the =< operator. However, this would work only when using the whole object. Example:
temp.something = TEXT
temp.something.value = 2427
...parameter.cObject =< temp.something
I suggest you go with the option 1 using the constants as the 2nd option is somewhat cumbersome.
You can copy the property but not by reference it.