I have question about file download with Extbase and FAL.
I can render image with
<f:image src="{file.uid}" alt="" width='100' height="100" treatIdAsReference="1"/>
I can get image, but I also have PDF file for download, and I can't use this ViewHelper.
Is there any other ViewHelper for file downloads?
If i dump that file i get this:
file => TYPO3\CMS\Extbase\Domain\Model\FileReferenceprototypepersistent entity (uid=1342, pid=310)
originalResource => NULL
uid => 1342 (integer)
_localizedUid => 1342 (integer)modified
_languageUid => 0 (integer)modified
pid => 310 (integer)
originalResource is null for file, and for image, image is printed with that ViewHelper. And I can't get file...
Any help is welcome...
You can use the publicURL property of the originalResource to create a file link.
Sample Fluid to generate a list of files referenced in your domain model property
<ul class="download-list">
<f:for each="{myObject.myFALproperty}" as="file" >
<li>{file.originalResource.title}</li>
</f:for>
</ul>
Just use the {myObject.myFALproperty} to see what you can access.
If you need more properties here are the basics of the Original and the reference in case you want to use the override located in the FlexForm
Original Attributes
filename :{myObject.myFALproperty.originalResource.originalFile.name}
title:{myObject.myFALproperty.originalResource.originalFile.title}
description:{myObject.myFALproperty.originalResource.originalFile.description}
alt:{myObject.myFALproperty.originalResource.originalFile.alternative}
uid:{myObject.myFALproperty.originalResource.originalFile.uid}
path:{myObject.myFALproperty.originalResource.publicUrl}
Reference Attributes
title: {myObject.myFALproperty.originalResource.title}
description {myObject.myFALproperty.originalResource.description}
Hope that helps.
Just for reference this is what the according TCA looks like, but you obviously already know that (note this sample has a maxitems setting of 10:
'myFALproperty' => array(
'exclude' => 0,
'label' => 'LLL:EXT:xy_sample/Resources/Private/Language/locallang_db.xlf:tx_xysample_domain_model_myobject.myFALproperty',
'config' =>
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'myFALproperty',
array('maxitems' => 10)
),
),
Step 1/2
You can get the URI to the PDF file like this:
In your FLUID Template:
<f:uri.image src="{file.uid}" treatIdAsReference="1"/>
OUTPUT
/path/to/your/pdf
This works even if "originalResource is null for file", like you stated in your question.
Step 2/2
Create a link in your FLUID Template (using inline notation)
<a href="{f:uri.image(src:'{file.uid}', treatIdAsReference: 1)}">
Download PDF
</a>
Test environment
typo3 v7.6.19
You can use the VHS viewhelper for that.
Check it out the following code:
<v:resource.file additionalAttributes="{foo: 'bar'}" data="{foo: 'bar'}" identifier="[mixed]" categories="[mixed]" treatIdAsUid="1" treatIdAsReference="1" as="NULL">
<!-- tag content - may be ignored! -->
</v:resource.file>
Link to the documentation:
https://fluidtypo3.org/viewhelpers/vhs/master/Resource/FileViewHelper.html
You have to install the vhs extension and also to add the namespace on your template file.
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
As a last thing you should have the files indexed in typo3. For that create a scheduler task and select the File Abstraction Layer: Extract metadata in storage task.
Related
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?
So I need to use the "isChildPage" viewhelper in fluid. However it does not work, and if I run
<f:debug>{item}</f:debug>
For the item/page in question I get nothing for childpage. Its sibling viewhelper "hasSubPage" however works fine, and both classes are located in the same Page folder in the vhs extension.
So I am at a loss.
My use of the code:
<v:menu pageUid="{parent}" entryLevel="2" class="sidebar-nav" includeSpacers="1">
<f:for each="{menu}" as="item">
<a href="{item.link}" class=" {f:if(condition: item.isChildPage, then: 'hidden', else:'nope')}">
There isn't an attribute for 'item' called 'isChildPage' in newer vhs versions (https://fluidtypo3.org/viewhelpers/vhs/master/)
Which output do you want to receive?
Use
{f:if(condition: item.pid > 0, then: 'hidden', else:'nope')}
or
{f:if(condition: item.pid == 0, then: 'nope', else:'hidden')}
item.pid is the UID of the parent page.
This will set class 'hidden' to all links except root page link.
I need a rush course on News (and some TYPO3). I would like to have a further 'what to display' plugin option, to show a customized list of news.
I (believe to) understand how to define a new mylistAction method within class newsController, and a corresponding mylist.html template.
What I miss is how I get a (working) mylist option within the BE module to insert the plugin into a page.
I am not sure what else I need to update and how (TCA, language files, TS, ... )
Thanks for your help, Cheers, mario
----- EDIT and SOLVED
I made it!
i defined action listmAction() within NewsController.php
i defined template listm.html
within Configuration/Flexforms/flexform_news.xml i added lines:
<numIndex index="22">
<numIndex index="0">LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:flexforms_general.mode.news_listm
</numIndex>
<numIndex index="1">News->listm</numIndex>
</numIndex>
within locallang_be.xlf i added lines
<trans-unit id="flexforms_general.mode.news_listm" xml:space="preserve">
<source>List m view</source>
</trans-unit>
Now i am able to insert a News plugin into a page with the
new listm option, and the listm template is rendered. (It seems I needed to trash cache too). Good!
It's a bad idea to modify the news extension - you can't really update it afterwards.
However, EXT:news has a built in way to add multiple list views, documented here.
Short version: There is a template selector in the news plugin, and you can add items to it through TypoScript. Put something like this in your pageTS:
tx_news.templateLayouts {
1 = A custom layout
99 = LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:flexforms_general.mode.news_listm
}
The choice you make in the backend in this field is passed to the views in the variable settings.templateLayout.
So in your List.html template file you can do this:
<f:if condition="{settings.templateLayout} == 99">
<f:then>
<!-- Render template with number 99 here -->
</f:then>
<f:else>
<!-- Render template with number 1 here -->
</f:else>
</f:if>
If you have multiple templates, it would be a good idea to use the switch/case-ViewHelpers from EXT:vhs or something similar.
If you want to insert the plugin into a page you need create custom frontend plugin for it. Something like
ext_tables.php:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'Namespace.' . $_EXTKEY,
'custom_news',
'Custom News'
);
ext_localconf.php:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Namespace.' . $_EXTKEY,
'custom_news',
array('CustomNews' => 'mylist'),
// non-cacheable actions
array('CustomNews' => 'mylist')
);
I hope you created custom extension for it and extended newsController.
Regards, Anton
I'm trying to access the settings of a Fluidtypo3 FCE element. My FCE is a news article that I want to include in another FCE, which is a slider. The slider only has one field and the configuration is the following:
<flux:field.relation
name="articles"
label="News-Beitrag"
multiple="true"
size="6"
table="tt_content"
condition="AND tt_content.pid = {record.pid} AND CType = 'fluidcontent_content' AND colPos = 1 AND sys_language_uid = {record.sys_language_uid}"
minItems="1"
maxItems="10"
renderMode="default"
/>
This configuration works, I can select all my news FCE's as a relation. The field articles saves the uid's of all referenced FCE's. Now I am trying to use these uid's to receive the content. Right now my code is the following:
<f:section name="Main">
<f:if condition="{articles}">
{v:iterator.explode(content: '{articles}', glue: ",", as: 'articles')}
{v:content.get(contentUids: "{articles}", render: 0) -> v:variable.set(name: 'slides')}
<f:for each="{slides}" as="element">
</f:for>
</f:if>
</f:section>
The <v:content.get> ViewHelper gets the tt_content record as it is recorded in the database. The flux settings are stored in XML-Format in the field pi_flexform. I am trying to access those specific flux settings one by one and not just the whole pi_flexform field in xml format.
I've looked for ViewHelpers that can convert XML to an Array and tried many other things, but nothing worked for me. I am grateful for any ideas how to solve this problem.
<flux:form.data> is the Viewhelper you seek. You can use it like this:
<f:for each="{slides}" as="element">
<flux:form.data table="tt_content" field="pi_flexform" record="{element}" as="flexformData">
<!-- Do stuff with flexformData -->
</flux:form.data>
</f:for>
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>