Fluid image with extra data for cycle2 - typo3

I'm using cycle2 for a image slider, for adding a title extra data is needed in the image url, so I want to generate the following url:
<img src="foto.jpg" data-cycle-title="Title" data-cycle-desc="Subtitle" />
I tried the following but this generates an error?
<f:image src="foto.jpg" data-cycle-title="Title" data-cycle-desc="Subtitle" />

Since data-cycle-title and data-cicle-desc are not registered arguments within the ImageViewHelper you cant pass those values directly.
But there is a additionalAttributes argument for the rescue. You can add as many attributes as you like to have in your image tag. additionalAttributes expects an array notation:
<f:image ... additionalAttributes="{data-cycle-title: 'Title', data-cycle-desc: 'Subtitle'}" ... />

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.

TYPO3 <f:image /> nest viewhelper or use the processed image somehow for lazyload

I'm trying to imply lazyload with a specific slider, it requests the src of the image to be entered twice, once as src and second as data-lazy like this:
<img src="domain.com/image.png" data-lazy="domain.com/image.png">
with <f:image /> I can use data="{lazy: 'domain.com/image.png'}" and should repeat the src of the image created with the viewhelper ... (typo3 documentation and the inline use of f:uri.image)
i have actually two questions:
how do I nest f:uri.image ? this gives an error <f:image src="{image.uid}" treatIdAsReference="1" data="{lazy: '{f:uri.image(src: {image.uid})}'}"/>
it should actually be the refference to the same
image, if I nest f:uri.image would I create a second rendered image ?
(especially because I also set width and height, but I wanted to keep the snippets simple)
the solution should work for TYPO3 v7 and v8
Try this
<img src="{f:uri.image(src : image.uid)}" data-lazy="{f:uri.image(src : image.uid)}" />
You don't have to use the <f:image ..> tag for creating the <f:uri.image ..> returns the same processed resource.
In loop:
<f:for each="{MARKER}" as="file">
<img class="lazy" src=".../blank.gif" data-lazy="{f:uri.image(image: file, width:'XXXc', height:'XXXc', treatIdAsReference:1)}" alt="{file.alternative}" title="{file.title}">
</f:for>

Output nested tags with one single ViewHelper

I have a TYPO3 project with an extension using Extbase and to implement lazy loading and retina images while maintaining compatibility if javascript is disabled, I need to generate some output like this:
<noscript data-src-small="small.jpg" data-src-large="large.jpg" data-width="300" data-height="200">
<img src="small.jpg" width="300" height="200">
</noscript>
So I wrote a custom ViewHelper (or rather I copied and modified an existing one) that does exactly this and it works, but I'm not sure I'm doing it right, because I'm manually creating the <img> like this:
$content = '<img class="'.$class.'" alt=" " src="'.$imageSource.'" width="'.$imageInfo[0].'" height="'.$imageInfo[1].'">';
$this->tag->setContent($content);
I wonder if there isn't a better way to do this, ideally I'd like to call the standard ImageViewHelper::render() function inside my custom ViewHelper.
Is there any way to do that? Should that even be done at all?
I am aware, I could adjust my template like this:
<x:noscript src="filename.jpg" width="300">
<f:image src="filename.jpg" width="300" />
</x:noscript>
(x:noscriptis supposed to be my custom ViewHelper)
and call renderChildren() inside my ViewHelper.
But then I would have to repeat src="filename.jpg" width="300" and I generally don't like to repeat input if there's a better way.
The easiest way to achieve what you want is to use a partial. It would look like this:
{namespace x=Yourcompany\Yourproduct\ViewHelpers}
<f:comment>
Parameters:
* src: src of the image
* width: Width of the image
</f:comment>
<x:noscript src="{src}" width="{width}">
<f:image src="{src}" width="{width}" />
</x:noscript>
You can use it like this:
<f:render
partial="Path/To/Partial"
arguments="{width: 300, src: 'filename.jpg'}
/>

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>

Put a href link into a Struts2 set tag

I want to put an anchor tag into a Struts2 variable that I can then display at various points in a JSP. That way I can avoid duplicating the complicated if/then statements that are used to build various forms of the href tag.
I'm using the Struts 's:set' tag to do this.
The problem is that Struts converts the '<' characters to htmlentities and when the page displays I see the actual "a href=someURL" tag displayed, not a working link.
If I add the "escape='true'" argument to s:set it does the same thing, only it displays the htmlentities for the '<' and '>' tags.
How do I put a valid anchor tag into a Struts2 variable and then display it as a working link?
Here's what I'm doing:
<s:set name="composerName">
<s:property value="'a href=%{viewRecordURL}>'" escape="false"/>
<s:property value="#composer.title" />
<s:property value="#composer.firstName" />
<s:property value="#composer.lastName" />
<s:property value="'</a>'" escape="false" />
</s:set>
Use s:url to create a valid url and then use it in s:a to generate the link.
You can refer the link below for more details:
http://struts.apache.org/2.1.8/docs/a.html
We can use url tag to create URL like mention below
<s:url id="hLink" action="yourStrutsActionName">
<s:param name="propertyName" value="%{propertyName}" />
</s:url>
<td><s:a href="%{hLink}"><s:property value="%{propertyName}"/></s:a></td>
do this easy way to set the link in Struts2
// add the Struts2 action in href
<s:a href="forgetPasswordPage.action" >Forget Password</s:a>
This isn't how you want to build this--what you have is two different things, a URL, and the text string of that url. The URL you already have. Only use <s:set> for the link text.
If you really need to, you can wrap this up into a JSP-based custom tag, but I wouldn't bother.
I'll answer my own question. Maybe someone else has a more elegant solution. Once again, we're trying to get both an anchor tag and a url into a s:set variable. The issues were two: 1) getting s:set to treat the tag string as a literal string and not an Object (which it wants to fetch from ActionContext or somewhere), and 2) turning off escaping so that the string text of the anchor tag isn't converted into htmlentities like '& lt;'.
For 1, I set the var to null, but provide a default argument, which s:property always treats as a literal string.
For #2, it's just a matter of using escape="false" in the right places.
Unfortunately, the string has to be built up with separate bits of s:property, but what can you do?
<s:set name="composerName" >
<s:property value="" default="<a href=" escape="false"/>
<s:property value="" default="'" />
<s:property value="%{viewRecordURL}" escape="true"/>
<s:property value="" default="'>" escape="false" />
<s:property value="#composer.title" />
<s:property value="#composer.firstName" />
<s:property value="#composer.lastName" />
<s:property value="" default="</a>" escape="false"/>
</s:set>
I haven't tested it yet with UTF-8 characters or potentially problematic characters like '&', apostrophe, or single quote in the #composer part.
I had the same issue, and I just solved it as following:
In the main bean, I have the following variables with Setters and Getters:
private int ReqNo;
private String hyperLinkToPage;
In the JSP page I have the TD as following:
<td class="displayValue" style="width: 10%;"><s:a href="%{hyperLinkToPage}"><s:property value="%{ReqNo}"/></s:a></td>
I hope that it will help.