Page's Resources Tab
I have been trying to access these files but with no luck. Any help is appreciated.
If your system has EXT:vhs installed you can get this via vhs viewhelper like this,
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
<v:page.resources.fal table="pages" field="media" uid="{page.uid}" as="images" slide="-1" >
<f:for each="{images}" as="image">
<f:image src="{image.url}" alt="{image.alternative} {image.name}" title="{image.title}" />
</f:for>
</v:page.resources.fal>
you can get more about this from here: https://github.com/FluidTYPO3/vhs/pull/395 and https://fluidtypo3.org/viewhelpers/vhs/2.3.3/Page/Resources/FalViewHelper.html#argument-slide
You can use typoscrpt solution as well,
lib.pageResources = FILES
lib.pageResources {
references {
table = pages
uid.data = uid
fieldName = media
}
renderObj = IMAGE
renderObj {
file {
import.data = file:current:uid
treatIdAsReference = 1
width = 150c
height = 150c
}
altText.data = file:current:alternative
titleText.data = file:current:title
}
maxItems = 3
}
Render this with:
<f:cObject typoscriptObjectPath="lib.pageResources" />
You can get more about this from here: https://riptutorial.com/typo3/example/21734/image-and-image-resource
Hope this helps you... #KeepCoding.. ;)
Regards
To access the Page Resources files / image in the TYPO3 Fluid, take this example:
<f:if condition="{files}">
<f:then>
<f:for each="{files}" as="image">
<f:uri.image image="{image}" />
</f:for>
</f:then>
</f:if>
all the Page Resources files / images find you in the "files". take the <f:debug>{_all}</f:debug>
Related
I am trying to get an Image from a custom content element into my fluid template. To achieve this I am using FilesProcessor.
custom element
Here is the corresponding code snippet from my setup.typoscript:
tt_content {
heiner_newcontentelement =< lib.contentElement
heiner_newcontentelement {
templateName = Default
dataProcessing.10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
dataProcessing.10 {
as = images
references.fieldName = image
references.table = tt_content
sorting = title
sorting.direction = descending
}
}
}
Showing what's available via f:debug-Viewhelper provides the following:
available variables in fluid template
So far, so good, what I have tried was to simply output the image in my fluid template with the following code:
<html data-namespace-typo3-fluid="true" xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"></html>
<f:layout name="Default" />
<f:section name="content">
<ul class="Das ist gut">
<f:for each="{images}" as="image">
<f:debug>{image}</f:debug>
<f:image image="{image}" height="250c" width="200c"/>
</f:for>
</ul>
</f:section>
</html>
although the variable "image" in the for-each loop is not empty, the image-viewhelper wont render anything. I am so desperate :( Somebody knows whats going wrong here? A lot of thx :)
According to the documentation, File Reference information are not always available in the fluidtemplate (see also https://docs.typo3.org/m/typo3/reference-coreapi/9.5/en-us/ApiOverview/Fal/UsingFal/Frontend.html#fluidtemplate).
What happens if you try this:
<ul class="Das ist gut">
<f:for each="{images}" as="image">
<f:debug>{image}</f:debug>
<f:image image="{image.originalFile}" height="250c" width="200c"/>
</f:for>
</ul>
What I would like to achieve is that an image changes depending on what language is selected at that moment.
This is my HTML
<f:if condition="{TSFE:sys_language_uid} == 1">
<f:then>
<f:link.page pageUid="{settings.rootpid}" class="navbar-brand">
<img src="fileadmin/branding/brand/images/png/image1.png" alt="Logo {settings.brandname}" />
</f:link.page>
</f:then>
<f:else>
<f:link.page pageUid="{settings.rootpid}" class="navbar-brand">
<img src="fileadmin/branding/brand/images/png/image2.png" alt="Logo {settings.brandname}" />
</f:link.page>
</f:else>
</f:if>
And this is my TS
[globalVar = GP:L = 1]
config {
sys_language_uid = 1
language = nl
locale_all = nl_NL.UTF-8
htmlTag_setParams = lang="nl" dir="ltr" class="no-js"
}
[global]
[globalVar = GP:L = 2]
config {
sys_language_uid = 2
language = fr
locale_all = fr_FR.UTF-8
htmlTag_setParams = lang="fr" dir="ltr" class="no-js"
}
[global]
I tried a ton of different ways of writing this but can't seem to make it work hopefully somebody can help.
I assume that you are using your own distribution, or extend the functionality of some package ...
Try this in your constants.ts (so they are available in the BE constant editor) myext/Configuration/TypoScript/constants.ts :
myext.configuration {
logo {
src {
# cat=myext/general/05; type=string; label=English Logo
default = fileadmin/branding/brand/images/png/image0.png
# cat=myext/general/06; type=string; label=Dutch Logo
nl = fileadmin/branding/brand/images/png/image1.png
# cat=myext/general/07; type=string; label=French Logo
fr = fileadmin/branding/brand/images/png/image2.png
}
}
}
then this in your setup.ts myext/Configuration/TypoScript/setup.ts :
page = PAGE
page {
# Page Main template
10 = FLUIDTEMPLATE
10 {
variables {
# Logo
logoSrc = TEXT
logoSrc.value = {$myext.configuration.logo.src.default}
}
}
}
[globalVar = GP:L=1]
page.10.variables.logoSrc.value = {$myext.configuration.logo.src.nl}
[end]
[globalVar = GP:L=2]
page.10.variables.logoSrc.value = {$myext.configuration.logo.src.fr}
[end]
now you can simply use {logoSrc} in your fluidtemplate
...
<f:link.page pageUid="{settings.rootpid}" class="navbar-brand">
<img src="{logoSrc}" alt="Logo {settings.brandname}" />
</f:link.page>
...
Pass the pre-evaluated boolean to the template. Either from your controller (there you have access to the TSFE) or via TS to the FLUIDTEMPLATE object. It's not clear from the question where you are coming from. You should move the condition inline into the src, this way you don't duplicate the whole markup, but only switch the value.
Alternatively, you can pre-calculate the src value in the controller or TS and just pass it to the view.
You can get current languageUid using viewHelper something like below.
You ViewHelper file.
<?php
namespace MyVendor\ExtensionKey\ViewHelpers;
class GetLangUidViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* GetLangUid
*
**/
public function render() {
return $GLOBALS['TSFE']->sys_language_uid;
}
}
In your fluid template get current laguageUid like below.
{namespace L=MyVendor\ExtensionKey\ViewHelpers}
<f:if condition="{L:getLangUid()} == 1">
<f:then>
<f:link.page pageUid="{settings.rootpid}" class="navbar-brand">
<img src="fileadmin/branding/brand/images/png/image1.png" alt="Logo {settings.brandname}" />
</f:link.page>
</f:then>
<f:else>
<f:link.page pageUid="{settings.rootpid}" class="navbar-brand">
<img src="fileadmin/branding/brand/images/png/image2.png" alt="Logo {settings.brandname}" />
</f:link.page>
</f:else>
</f:if>
I try to use the dataprocessor from TYPO3 8 to make my menu.
I have this code in my TypoScript script:
page = PAGE
page{
10 = FLUIDTEMPLATE
10 {
file = fileadmin/abis/templates/BootstrapTmpl.html
partialRootPath = fileadmin/abis/Partials/
layoutRootPath = fileadmin/abis/Layouts/
}
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
10 {
entryLevel= 0
excludeUidList = 27,30,31
levels = 5
#includeSpacer = 1
titleField = nav_title // title
as = huhu
}
}
...
}
And this one in a section:
<f:section name="myMenu" >
<f:debug title="title">{huhu}</f:debug>
<f:cObject typoscriptObjectPath="obj.logo" />
<ul class="nav navbar-nav navbar-left">
<f:for each="{huhu}" as="menuItem">
<li>
{menuItem.text}
<f:if condition="menuItem.subItems">
<f:render section="myMenu" arguments="{myMenu: menuItem.subItems}" />
</f:if>
</li>
</f:for>
</ul>
</f:section>
My HTML output is empty. The variable {huhu} is empty. And I don't know why. Does anybody have an idea?
Try to put your dataProcessing into page.10:
page = PAGE
page {
10 = FLUIDTEMPLATE
10 {
file = fileadmin/abis/templates/BootstrapTmpl.html
partialRootPath = fileadmin/abis/Partials/
layoutRootPath = fileadmin/abis/Layouts/
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
10 {
entryLevel= 0
excludeUidList = 27,30,31
levels = 5
#includeSpacer = 1
titleField = nav_title // title
as = huhu
}
}
}
}
First, the "dataProcessing" has to be done inside page.10. And second you have to give your arguments over to your section in the "f:render" tag. Don't know if you do that, because that part is missing in your example code.
I had a similar problem and my typoscript code was correct. However, I forgot to add
arguments="{_all}"
when calling
<f:render partial="header" arguments="{_all}" />
in my layout.
You can also use <f:debug>{huhu}</f:debug> in your Partial, if huhu is null you might have forgotten about the arguments="{_all}".
I have a typo3 fluid template in which I want to check if content exists before rendering some elements.
Is there an efficient way to do this?
eg.
<f:if condition="{contentInColPos0}">
<div class="section-content">
<f:render section="Main" />
</div>
</f:if>
Is there a built-in variable or a simple way to check content exists in a column position?
This is a common task in CMS templating (don't render this part unless there's something to show), but I can't seem to find how to do it simply.
There is no easy way to do that. But you can use some TypoScript and then pass the count to Fluid and use it in a condition:
lib.countContent = CONTENT
lib.countContent {
table = tt_content
select {
selectFields = count(uid) AS count
pidInList = this
andWhere = (deleted = 0 AND hidden = 0)
}
renderObj = COA
renderObj {
10 = TEXT
10 {
data = field:count
}
}
This object will output the number of content rows on the given page and can be accessed in Fluid:
<f:if condition="{f:cObject(typoscriptObjectPath:'lib.countContent')} > 0">
Then show some stuff
</f:if>
If you're going to use the content anyway and don't have global wrap in your content object, you can also use it directly because the Fluid IfViewHelper checks for empty strings. So e.g. this might be working even better:
lib.content < styles.content.get
(This object is empty if there is no content)
<f:if condition="{f:cObject(typoscriptObjectPath:'lib.content')}">
<f:then>
<f:format.html>{lib.content}</f:format.html>
</f:then>
<f:else>
No content found
</f:else>
</f:if>
Easyest way to check this with VHS and without TypoScript:
<f:if condition="{v:content.get(column:6) -> v:iterator.first()}">
<div class="myAmazingClass">
</div>
</f:if>
You can slide the content throug subpages if you want:
<f:if condition="{v:content.get(column:6, slide:'-1') -> v:iterator.first()}">
<div class="myAmazingClass">
</div>
</f:if>
Consider VHS with ViewHelpers https://fluidtypo3.org/viewhelpers/vhs/master/Content/GetViewHelper.html or https://fluidtypo3.org/viewhelpers/vhs/master/Content/RenderViewHelper.html combined with using the as argument and an f:if condition to check the assigned variable for being empty.
You can solve this easily:
In your TypoScript file:
lib.contentInColPos0 < styles.content.get
lib.contentInColPos0 t.select.where = colPos = 0
In your Template file:
<f:if condition="{f:cObject(typoscriptObjectPath:'lib.contentInColPos0')}">
<div class="section-content">
<f:render section="Main" />
</div>
</f:if>
Hi everybody out there,
I have configured my page template so that I can create FAL relations. I'm able to read the data of the current page and spit out the image.
But what I really want is that I can slide up - if there is no FAL relation at the current page then I would like to look in the parent page for an image - and the parents parent page if the parent itself have no FAL relation (and so on - until I'm at the root page).
After reading the documentation something like this is possible with content, but I can not find any hints how to do this with page resources.
Hopefully someone can help
Markus
You can use the vhs viewhelper v:page.resource in combination with the slide argument, wich is supported from vhs version 2.3.3.
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
<v:page.resources.fal table="pages" field="media" uid="{page.uid}" as="images" slide="-1" >
<f:for each="{images}" as="image">
<f:image src="{image.url}" alt="{image.alternative} {image.name}" title="{image.title}" />
</f:for>
</v:page.resources.fal>
Inline-syntax-example for the first element
<v:resource.image identifier="{v:page.resources.fal(field: 'media', uid: '{page.uid}' slide:'-1') -> v:iterator.extract(key: 'id') -> v:iterator.first()}" treatIdAsReference="1" maxWidth="1500"/>
It's not possible with a VHS ViewHelper because Resource / Record / FalViewHelper doesn't support content sliding like Content / GetViewHelper does. What you can do:
Write a feature request or make a pull request with your solution.
or
Write your own ViewHelper.
or
Use good old (or bad?) typoscript for it:
lib.slider = FILES
lib.slider {
references {
data = levelmedia:-1, slide
}
renderObj = COA
renderObj {
10 = IMAGE
10 {
file.import.data = file:current:publicUrl
file.width = 960
titleText.data = file:current:title
wrap = <li>|</li>
}
}
stdWrap.wrap = <ul>|</ul>
}
and use it in your template like:
<f:cObject typoscriptObjectPath="lib.slider" />
For TYPO3 8.7 you have to use TypoScript, vhs with v:page.resources.fal is not working anymore (issue) - in my case. See example from N1ck above.
I use a Subpage-Sitemap with images from page properties (media/resources).
FLUID:
<f:if condition="{menu}">
<ul class="ce-menu ce-menu-1">
<f:for each="{menu}" as="page">
<li>
<a href="{page.link}"{f:if(condition: page.target, then: ' target="{page.target}"')} title="{page.title}">
<f:format.raw>{page.title}</f:format.raw>
<f:cObject typoscriptObjectPath="lib.mediaResources" data="{uid:'{page.data.uid}'}" />
</a>
</li>
</f:for>
</ul>
</f:if>
TypoScript:
lib.mediaResources = FILES
lib.mediaResources {
references {
table = pages
#Seiten-ID ubergabe
uid.dataWrap= {field:uid}
fieldName = media
}
renderObj = IMAGE
renderObj {
file.width = 50c
file.height = 50c
file.import.data = file:current:uid
file.crop.data = file:current:crop
file.treatIdAsReference = 1
altText.data = file:current:title
params = class="ce-menu-1-image"
wrap = |
}
}
Works perfect, without vhs-Extension. A solution with FLUID would be nice.