How to output curly brackets in a TYPO3 Fluid template - typo3

By using this in a TYPO3 Fluid template
<f:uri.action arguments="{start: '\{start\}'}" [...] />
I would expect the following output
index.php?id=1&tx_plugin_pi1[start]={start}... // unescaped
index.php?id=1&tx_plugin_pi1%5Bstart%5D=%7Bstart%7D... // escaped
But I get this
index.php?id=1&tx_plugin_pi1[start]=\{start\}... // unescaped
index.php?id=1&tx_plugin_pi1%5Bstart%5D=%5C%7Bstart%5C%7D... // escaped
How can I get the expected result?
UPDATE: There is a feature request for this on forge: http://forge.typo3.org/issues/46257. But I still don't know how to get this fixed on a array like arguments.

I've found a solution inspired by http://forge.typo3.org/issues/46257#note-7 but without using a controller
<f:alias map="{ocb: '{', ccb: '}'}">
<f:uri.action arguments="{start: '{ocb}start{ccb}'}" [...] />
</f:alias>

Related

Remove trailing slash in path created by the ImageViewHelper

I am trying to add CSS code to a template file using Fluid. I want to render a background-image uploaded at /fileadmin/user_upload/foo.jpg
However, {images.0.url} returns the path /fileadmin/user_upload/foo.jpg/
with a trailing slash, which then of course throws the following error:
TYPO3Fluid\Fluid\Core\ViewHelper\Exception
Supplied file object type TYPO3\CMS\Core\Resource\Folder for must be File or FileReference.
How can I remove the trailing slash from the path?
Below, the relevant code snippet is shown. Please note that v:format.prepend is just used for debugging purposes here and has no effect on the issue.
<f:section name="Header">
<v:page.resources.fal table="pages" field="media" uid="{page.uid}" as="images" slide="-1" >
<v:asset.style name="header">
header#header <f:format.raw>{</f:format.raw>
background-image: url(<f:uri.image src="{v:format.prepend(add: '', subject: '{images.0.url}')}" treatIdAsReference="1" />)
<f:format.raw>}</f:format.raw>
</v:asset.style>
</v:page.resources.fal>
<f:render section="Default" partial="DefaultHeader" arguments="{_all}"/>
</f:section>
Do you think about the following?
You can remove the wrapping vhs ViewHelper and access the first media directly.
<v:asset.style name="header">
header#header <f:format.raw>{</f:format.raw>
background-image: url({f:uri.image(image:data.media.0})
<f:format.raw>}</f:format.raw>
</v:asset.style>
Faced a similar problem. Solved it by using absolute URLs of images. In my case it was (get URL):
<f:variable name="mediaUrl">{f:uri.image(image: mediaObject, treatIdAsReference: 1, absolute : 1)}</f:variable>
Later using URL as source:
data-src="{f:uri.image(src: mediaUrl, treatIdAsReference: 0)}"
I was switching sources between a provided obj and static resource uri based on condition, so this was necessary and came handy.

Fluid inline version of f:cObject with array in data

I try to form the following Fluid Viewhelper to a inline version:
<f:cObject typoscriptObjectPath="lib.infoBox" data="{pageUid: '{data.uid}', colPos: '7'}"/>
I tried a lot of things but what I thought it should be:
{f:cObject(typoscriptObjectPath: lib.infoBox, data: {pageUid: '{data.uid}', colPos: '7'})}
But unfortunately its not working. Whats the right line here?
I need to put it into an f:if to check if its empty.
Thanks.
Solution:
{f:cObject(typoscriptObjectPath: 'lib.infoBox', data: '{pageUid: \'{data.uid}\', colPos: \'7\'}')}
Note: the quotes in the inner values of the data array must be escaped.

TYPO3 Femanager Passwort additionalAttributes

I want to extend the additionalAttributes with a second Attribute. In the original Partials it looks like this:
<f:form.password
id="femanager_field_password_repeat"
name="password_repeat"
class="input-block-level"
value=""
additionalAttributes="{femanager:Validation.FormValidationData(settings:settings,fieldName:'password_repeat')}" />
I try this:
additionalAttributes="{femanager:Validation.FormValidationData(settings:settings,fieldName:'password'),placeholder: '{password_repeat}'}" />
With several Verions of Escaping the femanager:Validation..... Got this Error:
The argument "additionalAttributes" was registered with type "array",
but is of type "string" in view helper
"TYPO3\CMS\Fluid\ViewHelpers\Form\PasswordViewHelper“
Any Ideas?
I think
Validation.FormValidationData()
is a viewhelper that returns a whole array which is expected for the attribute "additionalAttributes".
Because of that it's difficult to extend the array at this place.
But as far as I know the femanager-viewhelper itself offers the possibility to extend the final array, all to do is to give your array as a further argument which is called 'additionalAttributes' as well.
A short example:
<f:form.password
property="password"
additionalAttributes="{
femanager:Validation.FormValidationData(settings:settings,
fieldName:'password',
additionalAttributes:'{required:\'required\',pattern:\'.{8,}\'}')}"
}" />
Notice the array of 2 values (required and pattern).
I also recommend to have a look at the viewhelper on github:
https://github.com/TYPO3-extensions/femanager/blob/master/Classes/ViewHelpers/Validation/FormValidationDataViewHelper.php

TYPO3 Ext. tx_news and absolute links for RSS View

i use the tx_news Extension and i need a absolute url to a single news.
The <n:link [...] /> build a correct link to an single news, but it's not a absolute link.
This don't working:
<n:link newsItem="{newsItem}" settings="{settings}" uriOnly="1" absloute="1" />
And with <f:uri.page absolute="1" /> i can't link to a single newsitem.
But i don't find any other way to build me a absolute link to a single news.
Maybe have someone a little resolution for this problem?
I need this for the RSS-Page for link to newsitems.
As stated in reference document this viewhelper gets optional configuration param which allows to pass an array of typolink settings.
<n:link newsItem="{newsItem}" settings="{settings}" uriOnly="1" configuration="{forceAbsoluteUrl:1}"/>
Use the additional configuration parameter of the n:link viewhelper. It expects an array of parameters as argument that are passed on to the typolink generation.
Important:
Make sure that you wrap more complex values in single quotes or you will end up getting errors. See the quoted value of additionalParams in this example:
<n:link newsItem="{newsItem}" settings="{settings}" configuration="{addQueryString:1, additionalParams:'&tx_news_pi1[#widget_0][currentPage]=3'}" title="{newsItem.title}">
...
</n:link>

How to disable automated encoding of special characters in fluid partials (TYPO3)

Should be simple enough. I'm trying to add an input field to a fluid partial in the extension "yag" (yet another gallery).
Input: <f:form.textfield id="live-filter" name="test" />
Output: <input id="live-filter" type="text" name="test" />
Somehow the code get's filtered along the way, but I don't know why.
TYPO3 v. 6.2
YAG v. 3.2.1
Edit: A wild guess would be some output filtering in TYPO3 itself, but where? I didn't set anything by purpose.
You need to traverse the path upwards to check if there is any fluid tag wrapped around it, that does escaping. In general, all tags do escaping.
Also check the code around <f:render partial....
It could also be that the TypoScript code that does calls the fluid template, has a .htmlspecialchars = 1 set.
Since TYPO3 8 there is another pitfall: Custom Viewhelpers do htmlspecialchars on the output unless told otherwise. The solution is:
<?php
namespace Vendor\ArTest\ViewHelpers;
class YourViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper{
/**
* As this ViewHelper renders HTML, the output must not be escaped.
*
* #var bool
*/
protected $escapeOutput = false;
As of TYPO3 ver. 9.5 and up to ver. 10.4 you could also wrap the output in the Fluid template into <f:format.htmlentitiesDecode> Tags like this:
<f:format.htmlentitiesDecode>
<f:form.textfield id="live-filter" name="test" />
</f:format.htmlentitiesDecode>
Further information on this can be found in the TYPO3 View Helper Reference.