tx_news: link to pdf in list view - typo3

I'm tyring to set up list view with tx_news and want to link a pdf file, that is also used as thumbnail directly in list view, not in detail view.
Tried
<a href="{relatedFile.originalResource.publicUrl -> f:format.htmlspecialchars()}" target="_blank">
But the link remains empty... Any suggestions?

The snippet as is looks ok, maybe the the loop around this link might not be in Order.
It should have structure like this:
<f:for each="{news}" as="newsItem">
<f:if condition="{newsItem.falMedia}">
<f:then>
<f:for each="{newsItem.falRelatedFiles}" as="falfile" iteration="i">
<li>
<span class="news-related-files-link">
<a href="{falfile.originalResource.publicUrl -> f:format.htmlspecialchars()}" target="_blank">
{falfile.originalResource.title}
</a>
</span>
<span class="news-related-files-size">
{falfile.originalResource.size -> f:format.bytes()}
</span>
<f:format.html>
falimage.uid : {falimage.uid}
identifier : {falimage.originalResource.identifier}
public_url : {falimage.originalResource.publicUrl}
name : {falimage.originalResource.name}
title : {falimage.originalResource.title}
alternative : {falimage.originalResource.alternative}
description : {falimage.originalResource.description}
extension : {falimage.originalResource.extension}
type : {falimage.originalResource.type}
mimeType : {falimage.originalResource.mimeType}
size : {falimage.originalResource.size}
creationTime : {falimage.originalResource.creationTime}
modificationTime : {falimage.originalResource.modificationTime}
</f:format.html>
</li>
</f:for>
</f:then>
<f:else>
</f:else>
</f:if>
</f:for>

Related

Why my DataProcessing\MenuProcessor don't show level-3 and level-4 for my page tree

I use Bootstrap_package v10 and Typo3 9, the menu processor doesn't show the level-3 and 4 for my pagetree.
I'm using the original templates from bootstrap package, the code is below:
10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
10 {
levels = 5
special = directory
special.value = 26969
expandAll = 1
includeSpacer = 1
as = mainnavigation
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = nav_icon
as = icon
if {
isTrue.stdWrap.cObject = COA
isTrue.stdWrap.cObject {
10 = TEXT
10.value = 1
10.if.isTrue = {$page.theme.navigation.icon.enable}
20 = TEXT
20.value = 1
20.if.isTrue = {$page.theme.navigation.dropdown.icon.enable}
}
}
}
}
}
and this is the fluid code :
<f:section name="MainNavigation">
<f:if condition="{menu}">
<ul class="navbar-nav">
<f:for each="{menu}" as="item">
<f:if condition="{item.spacer}">
<f:then>
</ul>
<ul class="navbar-nav">
</f:then>
<f:else>
<li class="nav-item{f:if(condition: item.active, then:' active')}{f:if(condition: item.children, then:' dropdown dropdown-hover')}">
<a href="{item.link}" id="nav-item-{item.data.uid}" class="nav-link{f:if(condition: item.children, then:' dropdown-toggle')}"{f:if(condition: item.target, then: ' target="{item.target}"')} title="{item.title}"{f:if(condition: item.children, then:' aria-haspopup="true" aria-expanded="false"')}>
<f:if condition="{theme.navigation.icon.enable} && {item.icon}">
<span class="nav-link-icon">
<f:if condition="{item.icon.0.extension} === svg">
<f:then>
<bk2k:inlineSvg image="{item.icon.0}" width="{theme.navigation.icon.width}" height="{theme.navigation.icon.height}" />
</f:then>
<f:else>
<f:image image="{item.icon.0}" alt="{item.icon.0.alternative}" title="{item.icon.0.title}" width="{theme.navigation.icon.width}" height="{theme.navigation.icon.height}" />
</f:else>
</f:if>
</span>
</f:if>
<span class="nav-link-text">{item.title}<f:if condition="{item.current}"> <span class="sr-only">(current)</span></f:if></span>
</a>
<f:if condition="{item.children}">
<ul class="dropdown-menu" aria-labelledby="nav-item-{item.data.uid}">
<f:for each="{item.children}" as="child">
<f:if condition="{child.spacer}">
<f:then>
<li class="dropdown-divider"></li>
</f:then>
<f:else>
<li>
<a href="{child.link}" class="dropdown-item{f:if(condition: child.active, then:' active')}"{f:if(condition: child.target, then: ' target="{child.target}"')} title="{child.title}">
<f:if condition="{theme.navigation.dropdown.icon.enable} && {child.icon}">
<span class="dropdown-icon">
<f:if condition="{child.icon.0.extension} === svg">
<f:then>
<bk2k:inlineSvg image="{child.icon.0}" width="{theme.navigation.dropdown.icon.width}" height="{theme.navigation.dropdown.icon.height}" />
</f:then>
<f:else>
<f:image image="{child.icon.0}" alt="{child.icon.0.alternative}" title="{child.icon.0.title}" width="{theme.navigation.dropdown.icon.width}" height="{theme.navigation.dropdown.icon.height}" />
</f:else>
</f:if>
</span>
</f:if>
<span class="dropdown-text">{child.title}<f:if condition="{child.current}"> <span class="sr-only">(current)</span></f:if></span>
</a>
</li>
</f:else>
</f:if>
</f:for>
</ul>
</f:if>
</li>
</f:else>
</f:if>
</f:for>
</ul>
</f:if>
</f:section>
The fluid is calling a page child but i don't know if it is recursive or not so it can showa all levels, what am I missing there, it seems like i'm the first one that having this issue ?
Thanks in advance for any help.
First you should verify if the data is available for more than the first two levels:
insert a <f:debug title="mainnavigation">{mainnavigation}</f:debug> in your template.
Then inspect your templates whether they are ready to display more than two levels.
I can imagine your templates show the first level, for second level a partial is called, but that partial does not call itself if necessary.
Except if you need some level specific markup (e.g. 'class="level1") you can build up menus by stacking the levels inside each other (giving stacked uls). So you either have a recursive call with stacked menus of the same markup or you define a partial for each level with individual markup (or you define a variable which contains the current level and call the partial recursive).
it's even worse: both levels are written out in the same template file, no partial (or section) is used.
I would change it to:
(I stayed with one file and instead of an additional partials I call a section, which can be in the same file)
<f:section name="MainNavigation">
<f:if condition="{menu}">
<ul class="navbar-nav">
<f:for each="{menu}" as="item">
<f:render section="subLevel" arguments="{item:item}" />
</f:for>
</ul>
</f:if>
</f:section>
<f:section name="subLevel">
<f:if condition="{item.spacer}">
<f:then>
<li class="dropdown-divider"></li>
</f:then>
<f:else>
<li class="nav-item{f:if(condition: item.active, then:' active')}{f:if(condition: item.children, then:' dropdown dropdown-hover')}">
<a href="{item.link}" id="nav-item-{item.data.uid}" class="nav-link{f:if(condition: item.children, then:' dropdown-toggle')}"{f:if(condition: item.target, then: ' target="{item.target}"')} title="{item.title}"{f:if(condition: item.children, then:' aria-haspopup="true" aria-expanded="false"')}>
<f:if condition="{theme.navigation.icon.enable} && {item.icon}">
<span class="nav-link-icon">
<f:if condition="{item.icon.0.extension} === svg">
<f:then>
<bk2k:inlineSvg image="{item.icon.0}" width="{theme.navigation.icon.width}" height="{theme.navigation.icon.height}" />
</f:then>
<f:else>
<f:image image="{item.icon.0}" alt="{item.icon.0.alternative}" title="{item.icon.0.title}" width="{theme.navigation.icon.width}" height="{theme.navigation.icon.height}" />
</f:else>
</f:if>
</span>
</f:if>
<span class="nav-link-text">{item.title}<f:if condition="{item.current}"> <span class="sr-only">(current)</span></f:if></span>
</a>
<f:if condition="{item.children}">
<ul class="dropdown-menu" aria-labelledby="nav-item-{item.data.uid}">
<f:for each="{item.children}" as="child">
<f:render section="subLevel" arguments="{item:child}" />
</for>
</ul>
</f:if>
</li>
</f:else>
</f:if>
</f:section>
Notice the changed markup for spacer in the first level!
Further changes might occur as I have not compared the code but concentrated on building up clean markup.
Increasing a 'parameter' for the recursion.
for an increasing value (level1, level2, level3...) you need a viewhelper in TYPO3 prior version 9:
this viewhelper can be realised in typoscript:
lib.math = TEXT
lib.math {
current = 1
prioriCalc = 1
}
then you can change the initial call to the SubLevel section to:
<f:render section="subLevel" arguments="{item:item,level:1}" />
Now you have a fluid variable level with the value 1.
the recursive call must be changed to:
<f:render section="subLevel" arguments="{item:child,level:{f:cObject(typoscriptObjectPath:'lib.math', data:'{level}+1')}}" />
for increasing values 2, 3, 4 ...
By default, MenuProcessor does not expand all levels. It will only show the branch you're on up to the level below the level you are on. If you want to show all levels for all branches you have to add expandAll = 1 to your configuration:
10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
10 {
levels = 5
expandAll = 1
...
}
Your Fluid template shows only 2 levels. By default in the Bootstrap package, you have a 2-level menu.
If you want to have more, you need to adjust the template to render more levels.
Here is the rendering of level 2 in your template:
<f:for each="{item.children}" as="child">
<f:render section="subLevel" arguments="{item:child}" />
</f:for>
If you want to render level 3, you need to go to the section subLevel and check if there are children of every item you set in arguments.
Example:
<f:if condition="{item.children}">
<ul>
<f:for each="{item.children}" as="level3Item">
...
</f:for>
</ul>
</f:if>
You should have some CSS for 5 levels of course. :)
I hope I could help you.
For levels beyond 2, I find it much easier to build in typoscript in your setup.typoscript.
lib.textmenu {
# We define the first level as text menu.
1 = TMENU
# The first level of this menu. 0 is rootline. -1 is 1 level up from rootline. 1 is 1 level down from rootline
entryLevel = 0
# UID's to exclude from the menu. Change this for each subsite, but will require a new template on each subsite.
excludeUidList = 21
# Turn spacers on, I use them to do sections of my menu.
1.SPC = 1
1.SPC.allWrap = <li class="a nav-item dropdown text-light bg-secondary SPC">|</li>
# Expand the whole menu - ie a sitemap
1.expAll = 1
# We define the normal state ("NO").
1.NO = 1
1.NO.wrap = <li class="nav-item NO">|</li>
1.NO.linkWrap = <li class="nav-item NO">|</li>
1.NO.ATagParams = class="nav-item dropdown NO"
# We define the active state ("ACT").
1.ACT = 1
1.ACT.wrapItemAndSub = <li class="nav-item active ACT">|</li>
# Get level 2 to get the format from level 1
2 <.1
# Do some customization for level 2
2.CUR = 1
2.CUR.wrapItemAndSub = <li class="nav-item dropdown active level2CUR">|</li>
2.CUR.ATagParams = class="active text-white"
# Make Levels 3 to 6 the same as level 1. I'll leave it to you to study all the typoscript wrapping.
3 < .1
4 < .1
5 < .1
6 < .1
}
Hello #Mohamed Masmoudi!
I am a newbie with TYPO3. I was asking myself the same question like you.
After a lot of research I found a solution which works for me (TYPO3 v10.4.12 and bootstrap-package) at least in desktop view mode.
But I don't understand what exactly is happening in mobile view. Maybe someone can give me a hint???
The sublevel is existing in source-code but is not showing up in mobile view.
First step was to modify the MenuProcessor in setup.typoscript
##########################
### DATA PREPROCESSING ###
##########################
dataProcessing {
1 = BK2K\BootstrapPackage\DataProcessing\ConstantsProcessor
1 {
as = theme
key = page.theme
}
10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
10 {
#modify these lines
levels = 5
expandAll = 1
includeSpacer = 1
as = mainnavigation
Second step modify the
/bootstrap_package/Resources/Private/Partials/Page/Navigation/Main.html
by adding the following lines to the fluid-template directly after the
<a href="{child.link}" class="dropdown-item{f:if(condition: child.active, then:' active')}"{f:if(condition: child.target, then: ' target="{child.target}"')} title="{child.title}">
...
</a>
here it comes:
<!-- 3rd Level -->
<ul class="dropdown-menu dropdown2-menu">
<f:for each="{child.children}" as="child2">
<li>
<a href="{child2.link}" class="dropdown-item{f:if(condition: child2.active, then:' active')}"{f:if(condition: child2.target, then: ' target="{child2.target}"')} title="{child2.title}">
<f:if condition="{theme.navigation.dropdown.icon.enable} && {child.icon}">
<span class="dropdown-icon">
<f:if condition="{child.icon.0.extension} === svg">
<f:then>
<bk2k:inlineSvg image="{child.icon.0}" width="{theme.navigation.dropdown.icon.width}" height="{theme.navigation.dropdown.icon.height}" />
</f:then>
<f:else>
<f:image additionalAttributes="{loading: 'lazy'}" image="{child.icon.0}" alt="{child.icon.0.alternative}" title="{child.icon.0.title}" width="{theme.navigation.dropdown.icon.width}" height="{theme.navigation.dropdown.icon.height}" />
</f:else>
</f:if>
</span>
</f:if>
<span class="dropdown2-text">{child2.title}<f:if condition="{child2.current}"> <span class="sr-only">(current)</span></f:if></span>
</a>
</li>
</f:for>
</ul>
<!-- End of 3rd Level -->
As you see I added a child2. You can add further sublevels like child3 etc by adding them after the particular <a>...</a>-tag
Don't forget to close all the open tags.
To separate the new sublevels by CSS I added a dropdown2-menu-Class to the tag.
Now you can add for example a .dropdown2-menu {margin-left: 50px} to your CSS.
Of course it is better not to touch the Bootstrap-Package. Instead use your own sitepackage. You can build one # https://sitepackagebuilder.com/
All of this is only to remember myself, what I was doing and maybe to help others... :-)

TYPO3 9.5.0 - pageUid of f:link.page not reading t3://page?uid=80

I have a TYPO3 9.5.0LTS and use the bootstrap package theme. It seems to be all working ... except ... when I add a link (internal or external) to a carousel item ... nothing gets rendered. The other elements come out fine.
I looked in the CalltoAction.html ... and found out that pageUid of f:link.page is not reading t3://page?uid=80.
When I {records} ... I get link => 't3://page?uid=80' (16 chars)
And when I test in CalltoAction.html:
<p>{item.data.link}</p>
<f:if condition="{item.data.link}">
<f:link.page pageUid="1" class="carousel-item-button btn btn-primary" additionalAttributes="{draggable:'false'}">
<f:if condition="{item.data.button_text}">
<f:then>
<span>{item.data.button_text}</span>
</f:then>
<f:else>
<span><f:translate key="readmore" extensionName="bootstrap_package" /></span>
</f:else>
</f:if>
</f:link.page>
</f:if>
<f:if condition="{item.data.link}">
<f:link.page pageUid="{item.data.link}" class="carousel-item-button btn btn-primary" additionalAttributes="{draggable:'false'}">
<f:if condition="{item.data.button_text}">
<f:then>
<span>{item.data.button_text}</span>
</f:then>
<f:else>
<span><f:translate key="readmore" extensionName="bootstrap_package" /></span>
</f:else>
</f:if>
</f:link.page>
</f:if>
I get the following result in the FE:
<p>t3://page?uid=80</p>
<a draggable="false" class="carousel-item-button btn btn-primary" href="/"><span>Read more</span></a>
<span>Read more</span>
So pageUid of f:link.page not reading t3://page?uid=80
How can I solve this?
the f:link.page-VH expects an integer (uid) in the parameter pageUid.
t3://page?uid=80 by way is no integer but a string. A special string which can be handled by the f:link.typo3link-VH

Listing files and folders with TYPO3 extbase fluid?

I have files array like
'file1.pdf',
'file2.pdf',
'file3.JPG',
'Folder1/file1.pdf',
'Folder1/Subfolder1/Subfolder-file1.txt',
'Folder2/text.txt',
'Folder2/file2.pdf'
For get list of files and folder I use following fluid
<f:for each="{files}" as="userFile">
<f:if condition="{userFile -> myext:explode(delimiter:'/') -> f:count()} == 1">
<f:then>
{userFile}<br />
</f:then>
<f:else>
<div class="folder">
<f:for each="{userFile -> myext:explode(delimiter:'/')}" as="segment" iteration="itemIteration">
<f:if condition="{itemIteration.isFirst}">
<f:then>{segment}</f:then>
<f:else>{segment}<br /></f:else>
</f:if>
</f:for>
</div>
</f:else>
</f:if>
</f:for>
I'm using my own explode view helper
And I get only list files and folders
file1.pdf
file2.pdf
file3.JPG
<div class="folder">Folder1</div>
file1.pdf
<div class="folder">Folder1</div>
<a href="">Subfolder1
Subfolder-file1.txt
<div class="folder">Folder2</div>
text.txt
<div class="folder">Folder2</div>
file2.pdf
How I can get listing like with fluid?
file1.pdf
file2.pdf
file3.JPG
<div class="folder">Folder1</div>
file1.pdf
Subfolder-file1.txt
Subfolder-file1.txt
<div class="folder">Folder2</div>
text.txt
file2.pdf
Is it possible?
In your Extbase Controller you can use the TYPO3\CMS\Core\Resource\ResourceFactory to get folders:
$resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
// Format [ID OF STORAGE]:[FOLDER]
$folder = $resourceFactory->getFolderObjectFromCombinedIdentifier('1:my/directory/to/scan');
$this->view->assign('folder', $folder);
Now you can use folowing partial in your fluid to walk the folders:
Partial/FolderRecusive.html
<f:for each="{folder.files}" as="file">
<a href={file.publicUrl}>{file.name}</a>
</f:for>
<f:for each={folder.subFolders} as="subFolder">
<f:if condition="{subFolder.files -> f:count()} > 0 OR {subFolder.subFolders -> f:count()} > 0">
<div class="folder">{subFolder.name}</div>
<f:render partial="FolderRecursive" arguments="{folder:subFolder}" />
</f:if>
</f:for>
In your Template put something like this to display the folders:
<f:render partial="FolderRecursive" arguments="{folder:folder}" />

Add to the second position of a Fluid array

Currently I have this code that wraps every 2 items with <li></li>
<f:for each="{modules}" as="module" iteration="loop">
<f:cycle values="{0: 1, 1: 0}" as="header">
<li>
</f:cycle>
...stuff here...
<f:cycle values="{0: 0, 1: 1}" as="footer">
</li>
</f:cycle>
</f:for>
Lets say {modules} = [A,B,C,D] and output is something like this:
<li>AB</li>
<li>CD</li>
What I need to do is add custom html to the second position. So my desired output is:
<li>AX</li>
<li>BC</li>
<li>D</li>
How can I do this?
To your updated question I would say, you may want to solve this issue with your own Helper class before adding modules to the View through the Controller.
It is however possible to build it simple in the template:
Here is the documentation about the for ViewHelper.
For simplicity I would do the following:
<f:for each="{modules}" as="module" iteration="loop">
<f:if condition="{loop.isFirst}">
<f:then>
<li>
{module}
##extra_code##
</li>
</f:then>
<f:else>
<f:if condition="{loop.isEven}">
<li>
</f:if>
...stuff here...
<f:if condition="{loop.isOdd} || {loop.isLast}">
</li>
</f:if>
</f:else>
</f:if>
</f:for>
Note: The first element will be "odd" because isOdd takes the current interation (based on "cycle"), which starts with 1.
For the first element there is your own block. You can take the first module and write your own code. It will run only once.
From the second element to the last it will use the 2 element in one li logic. Here is only one interesting thing, that we need take isOdd OR isLast to always close the last li, even if you have an even number of elements.
You can do this like below.
<f:for each="{modules}" as="module" iteration="iteration">
<f:if condition="{iteration.isFirst}">
<f:then>
<li>
</f:then>
<f:else>
<f:if condition="{iteration.index}%2">
<f:then></f:then>
<f:else><li></f:else>
</f:if>
</f:else>
</f:if>
<!--
Here Your Content
-->
<f:if condition="{iteration.isLast}">
<f:then>
</li>
</f:then>
<f:else>
<f:if condition="{iteration.cycle}%2">
<f:then></f:then>
<f:else></li></f:else>
</f:if>
</f:else>
</f:if>
</f:for>

TYPO3 Mask CE Accordion

I try to build a Mask CE element, an accordion.
As you can see here: http://www.pizzaworkshop.nl/index.php?id=3 it is partly working. Though I need some help to get this right (by lack of some good samples on the net).
this is what I have as fluid template (I,m using foundation6 :)
So all parts seems to be there but how to get the "repetition' in the html?
<f:if condition="{data.tx_mask_planned_header}">
<f:format.nl2br>{data.tx_mask_planned_header}</f:format.nl2br>
</f:if>
<ul class="accordion" data-accordion>
<li class="accordion-item" data-accordion-item>
<a href="#" class="accordion-title"><f:if condition="{data.tx_mask_workshop_gepland}">
<f:for each="{data.tx_mask_workshop_gepland}" as="data_item">
<f:if condition="{data_item.tx_mask_datum_workshop}">
<f:format.date format="d.m.Y">{data_item.tx_mask_datum_workshop}</f:format.date>
</f:if>
<f:switch expression="{data_item.tx_mask_soort_workshop}">
<f:case value="1">Pizza -Fun Workshop</f:case>
<f:case value="2">Pizza - Master Workshop</f:case>
<f:case value="3">Pizza - Midsummer Pizza</f:case>
</f:switch>
</a>
<div class="accordion-content" data-tab-content>
<h4>
<f:if condition="{data_item.tx_mask_workshop_state}">
<f:switch expression="{data_item.tx_mask_workshop_state}">
<f:case value="1"><b>Nieuwe workshop!<b/></f:case>
<f:case value="2">Deze workshop is vol!</f:case>
<f:case value="3">Nog enkele plaatsen beschikbaar</f:case>
</f:switch>
</f:if>
</h4>
<div class="callout">
<f:if condition="{data_item.tx_mask_workshop_info}">
<f:format.html parseFuncTSPath="lib.parseFunc_RTE">{data_item.tx_mask_workshop_info}</f:format.html>
</f:if>
<button class="button-red"> <f:if condition="{data_item.tx_mask_workshop_form_link}">
<f:link.page pageUid="{data_item.tx_mask_workshop_form_link}"></f:link.page>
</f:if>
</button>
</div>
</div>
</li>
</f:for>
</ul>
</f:if>
I have an accordion, where the accordion-content are own CEs. So my rendering consists of:
<ul class="accordion" data-accordion>
<f:for each="{data.tx_mask_accordionitems}" as="accordion_item">
<f:cObject typoscriptObjectPath="lib.tx_mask.content">{accordion_item.uid}</f:cObject>
</f:for>
</ul>
our mask definitions ...
... for Slider (only slider_elements allowed):
... the slider element:
... tabs (multiple CEs as subelements allowed):
your solution might differ if your CE definition might vary. please add the mask definition of your CE.