Remove trailing slash in path created by the ImageViewHelper - typo3

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.

Related

tinymce <span> gets removed when containing <br />

I'm using Tiny 4.9.10 to dynamically generate reports based on templates. Users can create templates which contain placeholders. These placeholders then get swapped out for their actual values when generating the actual report. The placeholders get their style (including font, which is the main issue here) from their enclosing <span>-tag.
When replacing the placeholder with their actual value, we use <br />-tags to insert new lines, since some of the placeholders are almost full reports on their own which need to be structured.
After the placeholders have all been replaced, we inject this dynamically generated content back into a Tiny editor, so as to allow users to make ad hoc changes to the content.
At this point however we noticed that the <span>-tag around a piece of generated content containing <br />-tags gets removed. This is a problem, because the style info that was enclosed in this tag gets removed as well, resulting in problems further down the line when generating a PDF.
What I've tried to work around this:
setting verify_html to false
adding +span[br]/+span[br /] to valid_children
setting forced_root_bloc to div
The first two options did nothing to help me, and while the last one looked promising, it didn't help, because even when using <div>, font info gets enclosed into a child <span>.
I know this is expected behavior, because <span> is an inline tag and so it shouldn't have <br /> tags as children, but I'm currently at a loss for a workaround which allows me to include <br /> tags into my dynamically generated content without losing the style (most importantly the font) of the parent tag.
So I solved this by replacing the <span> tags by <div> tags when we swap out the placeholders by using some regex looking for spans that enclose a <p>...<\p> or a <b />. This stops Tiny from throwing away the <span> tags when they contain either of these enclosed tags
TinyMCE considers the <span> <br /> </span> construct an empty space and deletes it in favor of optimization.
I may be late, but you can also try using this callback in the setup option to stop the editor from removing empty spans:
setup: function(editor) {
editor.on('PreInit', function() {
editor.schema.getElementRule('span').removeEmpty = false;
});
}

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).

TYPO3 FLUID STYLED CONTENT with Lazy Load Javascript Plugin

Unfortunately I'm still using TYPO3 7.6, but it's the same in principle like the latest TYPO3 CMS, so I also use Fluid_styled_content .. uff!
I've included the lazy load javascript plugin into my TYPO3-Website and now I try to change the FLUID-partial typo3conf/ext/myext/Resources/Private/Extensions/Fsc/Partials/MediaGallery.html - but I've a probem with this .. because my changing in line 'file' throws an error. I try it with or without " or \" ..
<f:section name="media">
<f:media
file="{f:uri.image(src: \"EXT:/myext/Resources/Public/img/icons/blank.gif\", treatIdAsReference:1}"
class="lazyload"
data="{src: '{f:uri.image(image: column.media)}'}"
width="{column.dimensions.width}"
height="{column.dimensions.height}"
alt="{column.media.alternative}"
title="{column.media.title}"
/>
</f:section>
I've changed file="{column.media}" , because I want to load my 'blank.gif' instead of the image himself.
Argument 1 passed to TYPO3\CMS\Core\Resource\Rendering\RendererRegistry::getRenderer() must implement interface TYPO3\CMS\Core\Resource\FileInterface, string given, called in C:\www\typo3_src-7.6.31\typo3\sysext\fluid\Classes\ViewHelpers\MediaViewHelper.php on line 90
The output is like this:
<img data-src="/fileadmin/user_upload/admins.jpg" class="lazyload" src="/fileadmin/user_upload/admins.jpg" width="280" height="176" alt="">
Lazy load is working perfect, but I have to load the blank.gif.
Is there a solution to manipulate the FSC-partials or do I need a new ViewHelper, like this?

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>

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>