ich verwende die Typo3 Extension: tx_news.
Bei der Ausgabe des Newstitel im Browser gibt es keine Probleme.
Ich frag mich aber ob es auch möglich ist die gewählte News-Kategorie als Browsertitel auszugeben?
Bevor der User zur gewählten Detail News kommt, durchläuft er schließlich einige Kategorien.
In meinem Fall wird immer “ Alexander Möller – Blog “ angezeigt statt die jeweilige Kategorie unter der sich die verschiedenen News befinden.
Viele Liebe Grüße Alex
If you take a look at the Detail.html you fill find something like that
<f:if condition="{newsItem.alternativeTitle}">
<f:then>
<n:titleTag>
<f:format.htmlentitiesDecode>{newsItem.alternativeTitle}</f:format.htmlentitiesDecode>
</n:titleTag>
</f:then>
<f:else>
<n:titleTag>
<f:format.htmlentitiesDecode>{newsItem.title}</f:format.htmlentitiesDecode>
</n:titleTag>
</f:else>
</f:if>
This is the code responsible for the title tag. You can add the category title by adding this additional code inside the f:format.htmlentitiesDecode tag:
<f:if condition="{newsItem.firstCategory}">
{newsItem.firstCategory.title}
</f:if>
Related
I am using TYPO3 9.5.20
I try to test a FLUIDTEMPLATE implementation and I get an Oops, ... with Section "PageHeader" does not exist.
Here my template file:
<f:layout name="Layout1ColumnPage" />
<f:section name="WholeContent">
<div id="whole-content">
<f:format.raw>{contentNormal}</f:format.raw>
<f:format.raw>{contentLeft}</f:format.raw>
<f:format.raw>{contentRight}</f:format.raw>
</div>
</f:section>
<f:section name="MainContent">
<div id="main-content">
<f:format.raw>{contentLeft}</f:format.raw>
</div>
</f:section>
<f:section name="SideContent">
<div id="side-content">
<f:format.raw>{contentRight}</f:format.raw>
</div>
</f:section>
<f:section name="PageHeader">
<div id="page-header">
<div class = "body" cellpadding="0" cellspacing="0">
<div class = "header w200">
<div class = "headTD">
<f:image src = "fileadmin/Page/Resources/Public/Images/Country-Radio-2020.jpg" alt="HeaderImage" />
</div>
</div>
--- Ende Image ---
</div>
</div>
</f:section>
<f:section name="PageFooter">
<div id="page-footer">
<div id="footer-notice"> <p>This is the page footer area.</p> </div>
</div>
</f:section>
Here my layout file
<div id="page">
<f:render section="PageHeader" />
<div id="page-body">
<div id="page-title">{data.title}</div>
<f:render section="WholeContent" />
<div id="page-body-end"> </div>
</div>
<f:render section="PageFooter" />
</div>
Here my setup file:
page = PAGE
page.typeNum = 0
page.10 = FLUIDTEMPLATE
page.10 {
format = html
# Pfad zu der HTML Vorlage der Webseite
// file = fileadmin/Page/Resources/Private/Templates/CRtemplate.html
templateName = CRtemplate
# Pfad zu eingebundenen Partials
partialRootPaths.1 = fileadmin/Page/Resources/Private/Partials/
# Pfad zur Layout Datei
layoutRootPaths.1 = fileadmin/Page/Resources/Private/Layouts/
# Pfad zur Layout Datei
templateRootPaths.1 = fileadmin/Page/Resources/Private/Templates/
file.cObject = CASE
file.cObject {
key {
data = levelfield: -1, backend_layout_next_level, slide
override.field = TSFE:page|backend_layout
}
# Einbindung des ersten HTML Templates
1 = TEXT
1.value = fileadmin/Page/Resources/Private/Layouts/Layout1ColumnPage.html
# Einbindung des zweiten HTML Templates
2 = TEXT
2.value = fileadmin/Page/Resources/Private/Layouts/Layout2ColumnPage.html
}
variables {
# Verknüpfung der Inhalte mit dem Backend Layout
contentNormal < styles.content.get
contentNormal.select.where = colPos = 10
contentLeft < styles.content.get
contentLeft.select.where = colPos = 11
contentRight < styles.content.get
contentRight.select.where = colPos = 12
}
}
In my opinion sections are defined in the right way. If I delete in the layout file render of PageHeader then I got the message that he cannot find section WholeContent. So it seems to be a general problem.
EDIT
As Bernd mentioned below, in Typo3 9.5.20 the setting of the rootPath is only possible as an area. example
templateRootPaths.1 = fileadmin/Page/Resources/Private/Templates/
But the 9.5 documentation still says, that both is possible!
Have also edited the above code!
I can't make out an error for sure, but there are some aspects you might consider for your templating:
Your templates miss an header with namespace declartions like
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:n="http://typo3.org/ns/GeorgRinger/News/ViewHelpers"
data-namespace-typo3-fluid="true">
:
</html>
You only define one path. That was usual in the beginning of fluid and replaced with paths arrays. (I don't know whether this still works with single path declarations)
# Pfad zur Layout Datei
templateRootPaths.1 = fileadmin/Page/Resources/Private/Templates/
# Pfad zu eingebundenen Partials
partialRootPaths.1 = fileadmin/Page/Resources/Private/Partials/
# Pfad zur Layout Datei
layoutRootPaths.1 = fileadmin/Page/Resources/Private/Layouts/
your template declaration is weird:
first you avoid a declaration of file by commenting
then you define a template by templateName
which is asided with a file.cObject where you miss that backend layouts might be declared in pageTS and are no longer just numbers (no default value in case)
Meanwhile you can get the evaluation of backend_layout and backend_layout_next_level with the core defined typoscript data pagelayout which results in the simple declaration:
page.10 {
templateName {
data = pagelayout
ifEmpty = default
}
}
You might add a special fluid variable to debug the values in the backend_layout fields:
page.10 {
variables {
pagelayout = TEXT
pagelayout.data = pagelayout
}
}
minor topics:
Don't store your templates in fileadmin/. Use a site extension.
{variable->f:format.raw()} is shorter and most times more readable than <f:format.raw>{variable}</f:format.raw>
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
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>
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>
I define an array in my extensions setup.txt typoscript like so:
settings{
halls {
0 = Default
1 = Mississauga
2 = Halifax
3 = Niagara Falls
4 = Oakville
5 = Pickering
}}
how in my fluid template can I find the length of the halls array? I want an if condition to do one thing if length is greater than 1 and another if not.
I am using typo3 v4.5.32 with extbase 1.3.
Thank you.
I tried this but it puts out two <th> tags instead of just one. The first if is meant to prove that there is more than one element, the next is meant to print out a <th> only if it is the first element.
<f:for each="{settings.halls}" as="hall" key="number" iteration="itemIteration">
<f:if condition="{itemIteration.isFirst != itemIteration.isLast}">
<f:if condition="{itemIteration.index == 0}">
<th>
<f:translate key="tx_bpscoupons_domain_model_coupon.hall" />
</th>
</f:if>
</f:if>
</f:for>
Why?
UPDATE: here is my work around for a lack of "is array length > 1" ferature in fluid
<f:for each="{settings.halls}" as="hall" key="number" iteration="itemIteration">
<f:if condition="{itemIteration.isFirst}">
<f:then>
<f:if condition="{itemIteration.isLast}">
// if both first and last there is only one so skip
</f:if>
</f:then>
<f:else>
<f:if condition="{itemIteration.isLast}">
//if there is more than one element in halls then eventually you'll get here once so print out th tags
<th>
<f:translate key="tx_bpscoupons_domain_model_coupon.hall" />
</th>
</f:if>
</f:else>
</f:if>
</f:for>
and to print out data:
<f:for each="{settings.halls}" as="hall" key="number" iteration="itemIteration">
<f:if condition="{itemIteration.isFirst}">
<f:then>
<f:if condition="{itemIteration.isLast}">
<f:then>
</f:then>
<f:else>
<f:if condition="{number} == {coupon.hall}">
<td>{hall}</td>
</f:if>
</f:else>
</f:if>
</f:then>
<f:else>
<f:if condition="{number} == {coupon.hall}">
<td>{hall}</td>
</f:if>
</f:else>
</f:if>
</f:for>
ugly but seems to work.
UPDATE 2 :
DOH!!! I missed total, just what I needed but I was looking for length or count, so this code is what I want:
<f:for each="{settings.halls}" as="hall" key="number" iteration="itemIteration">
<f:if condition="{itemIteration.total} > 1">
<f:if condition="{itemIteration.isLast}">
<th><f:translate key="tx_bpscoupons_domain_model_coupon.hall" /></th>
</f:if>
</f:if>
</f:for>
You can find a length of an array with the f:count ViewHelper. Just like other ViewHelper it can be used as an inline notation (You can find more here)
The correct code would be:
<f:if condition="{settings.halls -> f.count()} > 1">
<f:then>
//your code for then
</f:then>
<f:else>
//your code for else
</f:else>
</f:if>
<f:if condition="{f:count(subject: settings.halls)} > 1"> do something </f:if>
see update#2 above for the answer. to reiterate:
<f:for each="{settings.halls}" as="hall" key="number" iteration="itemIteration">
<f:if condition="{itemIteration.total} > 1">
<f:if condition="{itemIteration.isLast}">
<th><f:translate key="tx_bpscoupons_domain_model_coupon.hall" /></th>
</f:if>
</f:if>
</f:for>
For those of you who are looking for a custom viewhelper for this:
class ArrayCountViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* Get array count
*
* #param mixed $array
* #return string
*/
public function render($array) {
if (!is_array($array))
return 0;
return count($array);
}
}