I am wondering what's the best solution to get my problem solved.
I have a folder with zip files containing images and want to import the images into my extension. In a perfect world I want to do this using FAL and not manually - is there a way to do it?
Thanks a lot, your help is really appreciated.
You could upload your images to the Public folder of your extension or to fileadmin and then use VHS View Helper to get the images in your extension with v:media.files
https://fluidtypo3.org/viewhelpers/vhs/master/Media/FilesViewHelper.html
Then use a for loop:
https://fluidtypo3.org/viewhelpers/fluid/master/ForViewHelper.html
and the f:image:
https://fluidtypo3.org/viewhelpers/fluid/master/ImageViewHelper.html
This should look something like this:
<f:alias map="{myimages: {v:media.files(path: 'EXT:myext/Resources/Public/myimages', extensionList: '''', prependPath: 1, order: '''', excludePattern: '''')}">
<f:for each="{myimages}" as="myimage">
<f:image src="{myimage}" alt="alt text" />
</f:for>
</f:alias>
Related
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).
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?
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>
I use TYPO3 7.6.2 and fluid_styled_content. With Gridelements my Code look like this:
<div class="col-md-12 col-sm-12">
<div id="c8">
<h6>Test</h6>
</div>
</div>
How can I remove the "div id="? If I use "css_styled_content" there is no problem.
Thanks
The whole rendering is defined inside the fluid templates (as the extension name suggests). So you are able to overwrite the folder containing the layouts / templates and modify them to your needs.
In case of "fluid_styled_content" the configuration is done in TypoScript, so add lib.fluidContent.layoutRootPaths.30 = /path/to/your/layouts, copy the original layouts from EXT:fluid_styled_content/Resources/Private/Layouts/ to your path and modify them to fit your needs.
In your case you have to remove the line:
<div id="c{data.uid}">
in all three layouts.
Further information are available at https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.3/Feature-66111-AddTemplaterootpathsSupportToCobjectFluidtemplate.html
#Daniel
Thanks for the hint.
Works for me too, but I had to add
lib.fluidContent.templateRootPaths.30 = EXT:extension/Resources/Private/Templates/
to my configuration, because, in my case I want to edit Textmedia.html and thats in Templates folder.
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'}
/>