Fluid inline version of f:cObject with array in data - typo3

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.

Related

TYPO3 (Fluid): Generate FAL-SVG-Image as inline code

Is there a fluid pendant to the new TS option Feature: #82091 - Allow inline rendering in SVG content object or a workaround?
The only solution i see(atm) is to write my own viewhelper or i am missed something?
You can define a typoscript object in your root template:
lib.inlineSvg = SVG
lib.inlineSvg {
renderMode = inline
src.field = src
}
(see SVG cObject). Then in your fluid you can do this:
<f:cObject typoscriptObjectPath="lib.inlineSvg" data="{src: 'path/to/the/file.svg'}" />
Of course this limits you to cases in which you have the actual path to the image. You cannot (directly) reference a FAL object. You can, however, just get the files public url:
<f:cObject typoscriptObjectPath="lib.inlineSvg" data="{src: filereference.publicUrl}" />
or
<f:cObject typoscriptObjectPath="lib.inlineSvg" data="{src: filereference.originalResource.publicUrl}" />
depending on whether you are in Extbase cotext or not (see the documentation). You can also pass all other options the cObject takes in the data argument of the f:cObject ViewHelper (e.g. width).

TYPO3 Fluid dynamic key in arguments

I would like to render a partial with dynamic keys for the arguments.
In the partial:
<f:link.action action="{action}" controller="{controller}"
arguments="{'{argument1name}': argument1, '{argument2name}': argument2}">
{bla}
</f:link.action>
So can argument1name and argument2name be written dynamicly in Fluid? What is the syntax, above is obviously wrong. Even better would be an array with an unknown number of arguments.
I came up with a solution for my problem. In the Fluid Template..
<f:variable name="modalArguments" value="{organization: organization, contactperson: contactperson}"/>
<f:render partial="Components/ActionModal" arguments="{modalTitle: 'Bla', modalBody: 'Are you sure {contactperson.name} bla?', action: 'delete', controller: 'Contactperson', modalArguments: modalArguments}"/>
In the partial something like
<f:link.action action="{action}" controller="{controller}" arguments="{modalArguments}" class="btn btn-primary">bla</f:link.action>
So it's possible to throw the arguments array in a variable.
As in fluid the key for arrays never is wrapped in ' your syntax obviously is wrong.
If a value is wrapped in ' it is constant text, otherwise it is interpreted as variable. So keys are handled in another ways than values.

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.

How to output curly brackets in a TYPO3 Fluid template

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>

Zend Frameword 2: How to set a html link (img) in a legend of the fieldset?

I used zf2 to design a website.
And the form is something like this:
$this->add(array
'options'=>array(
'label'=> 'title1'))
And finally it shows like this:
<form>
<fieldset>
<legend>title1</legend>
<label>****</label>
</fielset>
</form>
Now, I wanna add a link or an image after the title1, for example:
<form>
<fieldset>
<legend>title1<a href=''>link</a></legend>
<label>****</label>
</fielset>
</form>
How can I do this?
You can't. Well, at least not without overwriting the specific ViewHelper (probably formCollection()). In ZF2 all Labels are run through the Zend\View\Helper\EscapeHtml ViewHelper. Therefore using any sort of HTML inside Labels is not supported in any way.
While going by specification it may be allowed to use inline-elements inside the <legend> Element, semantically it looks a little different. The <legend> shall do nothing but to describe the contents of the <fieldset>.
Anyways, opinions aside, as i've mentioned, you'll have to overwrite the ViewHelper and then skip the use of the EscapeHtml ViewHelper, as it's done in this line of the formCollection() Code