TYPO3: Pass multiple arguments to a partial from a fluid template - typo3

I have a fluid template, from where I call an often used snippet (called "partial"):
Template:
<f:render partial="fbLikeBox" arguments="{settings}"/>
Partial fbLikeBox.html:
<div id="fb-root"></div><script src="http://connect.facebook.net/xxxxxxxx"></script>
<fb:like href="{settings.baseURL}/details/?guide_uid={audioguide.uid}">
</fb:like>
As you can see, I need both values from the {settings} and the {audioguide} array passed to the partial. How can I achieve that?

Starting with TYPO3 4.6, you could just use
<f:render partial="fbLikeBox" arguments="{_all}" />
The {_all} will simple make sure all variables currently available in your template, are available in the partial.

you can use an array, like:
<f:render partial="fbLikeBox" arguments="{settings : settings, audioguide:audioguide}"/>
They're key : value pairs where the value defines the accessible name in your partial

Related

Controller action - redirect to another template

I am looking for a way to redirect to another template if certain conditions are fulfilled.
Like:
public funtion redirectAction() {
if(certain conditions = TRUE){
REDIRECT TO ANOTHER TEMPLATE WITH DIFFERENT CONTENT
}
}
I've seen some expressions in existing actions:
$this->redirect('list');
In this case, 'list' is the default List.html template, right?
So I thought if I replaced the 'list' with a different template name, that would solve the problem. But i get a opps error.
Or is there any other solution of calling a different template?
Thank you very much!
with a redirect in the controller you always redirect to another function, not a template.
For example with
$this->redirect('list2');
You would then redirect to the function list2Action() and this would expect a Template List2.html
Often however, it is easier to use a switch in fluid.
for example:
<f:if condition="{abc} == 1">
<f:then>
<f:render partial="TempalteAbcTrue" arguments="{_all}" />
</f:then>
<f:else>
<f:render partial="TempalteAbcFalse" arguments="{_all}" />
</f:else>
If you used the normal folder structure of extbase you have a "Layouts", "Templates" and "Partials" folder.
With the example above you can create 2 files in the folder "Partials": "TempalteAbcTrue.html" and "TempalteAbcFalse.html".

TYPO3 - how to properly define constant, store it into variable and use inside of fluid template

In the Fluid template of plugin I am working on, some things are hardcoded. For instance:
<f:else>
<li>
<v:page.link pageUid="114" />
</li>
</f:else>
Since pageUid values are not same on test and production server I would like to make this more dynamic.
I would like to store this somehow in variable and then use the variable in the fluid template.
I just dont know hot to make this and where in TYPO3.
Thanks in advance!
Because it is an setting do it like this:
Constants:
plugin.myext.settings.detailPid = 123
Setup:
plugin.myext.settings.detailPid = {$plugin.myext.settings.detailPid}
Variables are for variable content. If you have the same PID using variables with TEXT or similiar is overdressed and settings are the correct way.
Also variables are only accessable for FLUID_TEMPLATE content element, not for plugins!
Also in your extbase controller you can access these settings by simple access $this->settings['detailPid']without to render the cObjects first.
In your fluid you can access settings by {settings.detailPid}.
In typoscript template for your content object FLUIDTEMPLATE:
Typoscript setup/configuration:
10 = FLUIDTEMPLATE
10 {
variables {
pageUid = TEXT
pageUid.value = 114
}
}
or using constants
Typoscript constants:
pageUid = 114
Typoscript setup/configuration:
10 = FLUIDTEMPLATE
10 {
variables {
pageUid = TEXT
pageUid.value = {$pageUid}
}
}
Then you can fetch pageUid in your Fluid HTML
<f:else>
<li>
<v:page.link pageUid="{pageUid}" />
</li>
</f:else>
To use variables in a Fluid partial, make sure to pass these along, e.g. by providing _all:
<f:render partial="fluid_part_header" arguments="{_all}" />
If you use EXT:vhs anyways, you can do the following to:
TS-Constants:
pageUid=114
TS-Setup:
settings.pageUid = {$pageUid}
Template (Fluid)
<f:else>
<li>
<v:page.link pageUid="{v:variable.typoscript(path: 'settings.pageUid')}" />
</li>
</f:else>
This will make it available for all FLUID Templates.
Please consider using jokumer's solution.
randomresult's solution would work, but I wouldn't suggest it. You don't need vhs to pass variables.
Not talking about Paul Beck`s solution, because it wouldn't work at all. Not anymore at least. (See TYPO3\CMS\Fluid\ViewHelpers\CObjectViewHelper, https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/CObject.html). It accepts only content objects.
Set your Pid in constants like PID_SOME_PAGE = 123 and set a variable in your plugins settings. Like this:
plugin.tx_yourplugin {
...
settings{
somePage = {$PID_SOME_PAGE}
}
...
}
You can bypass that constants version if you want and set your page id in settings directly. It's just a cleaner way in my opinion, especially for larger websites.
Then you can use that variable in your template, like this <f:link.page pageUid="{settings.somePage}">Go to Page</f:link.page>. More options for f:link.page here: https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/Link/Page.html

In TYPO3 Fluid, how to pass additional arguments to a partial when {_all} is used

Fluid Styled Content uses the f:render Viewhelper as such:
<f:render partial="Header" arguments="{_all}" />
I'd like to pass another info to the partial, like
<f:render partial="Header" arguments="{_all, settings : doThis}" />
But it seems to me that's the wrong way, as it throws an error.
I also tried accessing settings.doThis with f:alias, but no luck (or rather, skill) either.
How's that done correctly?
This is possible with the alias ViewHelper. I already used it with TYPO3 version 6 and 7.
Just extend the {_all} var as following
Partial
<f:alias map="{additionalVar: 'foobar'}">
<f:render partial="Partial" arguments="{_all}"/>
</f:alias>
Section
<f:alias map="{additionalVar: 'foobar'}">
<f:render section="Section" arguments="{_all}" />
</f:alias>
You can use the "additionalVar" variable as any other.
It is working with section and partial.
You can't, so just modify your settings (or any other var) in the controller yet or use ViewHelper, which allows you to declare vars in the view, like i.e.: v:variable.set of VHS ext.
It is possible to use this one, but donĀ“t use the var 'settings'. This one is used by typoscript.
<f:render partial="Header" arguments="{_all, myvar:'myvalue'}" />
Try the <f:debug> tag in the Header Partial and see
You can use vhs viewhelper with fluid like below.
<v:variable.set value="{yourValue}" name="variable">
<f:render partial="Header" arguments="{_all, newVar:variable}" />

How to make circle with break in fluid?

I want to stop my circle after output first element.
<f:for each="{errors}" as="error">
<f:switch expression="{error.code}">
<f:comment>The given subject was not a valid email address</f:comment>
<f:case value="1221559976">
<f:translate extensionName="helper" key="validator.emailaddress.notvalid" />
</f:case>
...
</f:switch>
BREAK????
</f:for>
Is it possible with fluid? Regards, Anton
You don't even need to iterate the collection, what for? Instead you can just fetch first element like: {errors.0}
Additionally if you want to fetch i.e. first 3 elements, you can prepare $limitedErrors (or smth) in your PHP controller and then assign it into the view.
It will be still more comfortable than manipulating within the template engine.
You can make you for each loop with additional argument iteration=""
add below code
<f:for each="{errors}" as="error" iteration="errorIterator">
and add condition
<f:if condition="{errorIterator.index} = 0">
or
<f:if condition="{errorIterator.isFirst}">
May you can use vhs viewhelper
<v:switch value="{variable}">
<v:case case="someValue" break="TRUE">
<!-- do whatever, if {variable} == 'someValue' -->
</v:case>
<v:case case="default">
<!-- the case "default" is a reserved keyword which acts as the default case. -->
</v:case>
</v:switch>
break > boolean

FLUID ViewHelper form in new window

I would like to add the target attribute to a FLUID form, so that after submitting the form, a new window is created.
This does not work, and produces an error:
<f:form target="_blank" action="..." name="..." id="..." pageUid="..." controller="..."></f:form>
Any ideas on how to make the to open in a new window?
I use TYPO3 6.2beta5
As the f:form ViewHelper inherits from the AbstractTagBasedViewHelper, it shares the same allowed attributes.
The fluid documentation inside the TYPO3 Flow documentation shows you all allowed attributes.
To answer your question, the correct way to use it would be:
<f:form additionalAttributes="{target:'_blank'}">FORMCONTENT</f:form>
Note that the additionalAttributes argument is an array. If you were to add more than 1 custom attribute, you would do it like that:
<f:form additionalAttributes="{target:'_blank', data-validate: 'foo'}">FORMCONTENT</f:form>
EDIT
The AbstractTagBasedViewHelper changed, so the answer as of today for TYPO3 CMS v7 would be: There's an attribute data for that which takes an array of keys and values.
<f:form data="{foo: 'bar', validate: 'baz'}" ....>
FORMCONTENT
</f:form>