TYPO3 Ext. tx_news and absolute links for RSS View - typo3

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>

Related

fluid template: render image only if it exists

How can I use f:if to see if an image exists on the server before trying to render it?
I have tried the following without success:
<f:if condition="fileadmin/bilder/Header/{data.title}.jpg">
<f:then>
<f:variable name="imageUri" value="fileadmin/bilder/Header/{data.title}.jpg" />
</f:then>
<f:else>
<f:variable name="imageUri" value="fileadmin/bilder/Header/default.jpg" />
</f:else>
</f:if>
{data.title} works correkt. The Problem is that my condition is wrong. It never goes to the else. Probably my condition is interpret as a string und not as an source.
Description here doesn´t help because my Image is on the server.
Render image in fluid template if it exists?
First of all, why would you have a hardcoded path to a file in fileadmin in a template? That's very uncommon, most of the time you have some kind of relation through TYPO3 (e.g. through the media field in the pages table or something like that).
If this is still something you need, you'd have to write a FileExistsViewHelper that checks if the file exists before using it. Here's the documentation on how to write a custom view helper: https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/8-Fluid/8-developing-a-custom-viewhelper.html
You'd need to register your filename as an argument with registerArgument and then prepend the path to the TYPO3 installation (to make it an absolute path) and check for this file with file_exists.
Extend from \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper and implement the verdict method.
Your template above just creates a string (as you already guessed).

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.

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

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>

Fluid generate URI of another extension in TYPO3

I have a Typo3 Extbase plugin called "PluginOne".
And I have to call another Controller Action of the "PluginTwo" in "PluginOne".
How is it possible...
I tried this in PluginOne
<f:uri.action action='show' controller='Gallery' extensionName='PluginTwo' pluginName='PluginTwo' />
But it gnerate the wrong url, the generated url contains ID of the Current Plugin ie 'PluginOne'.
you can use
<f:uri.action action="list" controller="Inquirer" extensionName='PluginTwo' pluginName='PluginTwo' arguments="{uid: 1}" pageUid="62" />
this one,
it works for me