I want to implement responsive image rendering according to the different scale (media) in TYPO3 using sourceCollection?
<picture>
<source src="fileadmin/_processed_/imagefilenamename_595cc36c48.png"
media="(max-device-width: 600px)" />
<source src="fileadmin/_processed_/imagefilenamename_42fb68d642.png"
media="(max-device-width: 600px) AND (min-resolution: 192dpi)" />
<img src="fileadmin/_processed_/imagefilenamename_595cc36c48.png" alt="" />
</picture>
I can render it using TypoScript but how can i use this in my own extension?
Thanks in advance.
The most straight-forward way is to use TypoScript. In the example below we use the same configuration I use for tt_content to render News items.
First of all you need to define a TypoScript object that uses the file that is passed to the object. Then you copy the configuration that is used for tt_content.
lib.responsiveImage {
default = IMAGE
default {
file.import.current = 1
altText.data = field:altText
titleText.data = field:titleText
layoutKey = picturefill
layout.picturefill < tt_content.image.20.1.layout.picturefill
sourceCollection < tt_content.image.20.1.sourceCollection
}
}
(You may need to change the example to another layout if you don't want to use picturefill.)
Then, in Fluid, you pass the image to TypoScript. The example below maps the uri of a FileReference:
<f:alias map="{image: {uri: '{f:uri.image(src:\'{mediaElement.uid}\', treatIdAsReference:\'1\')}', altText: mediaElement.originalResource.alternative, titleText: mediaElement.originalResource.title}}">
<f:cObject typoscriptObjectPath="lib.responsiveImage.default" data="{image}" currentValueKey="uri" />
</f:alias>
You can also define other configuration, e.g.
lib.responsiveImage {
default = IMAGE
default {
[...]
}
newsDetail < .default
newsDetail {
[different configuration for type newsDetail]
}
}
Related
I want to adjust my rendering of layout and frame elements in the frontend.
I have different layouts defined via typoscript. Now I want to define two frames, that should adjust the wrapped elements on layout level.
Currently the two layers (layout and frame) gets rendered like the following:
(exact classes might differ)
<div class="layout-class">
<div class="frame-class">
<p>This is Content</p>
</div>
</div>
I want to change that behaviour via Typoscript to render it like the following:
<div class="layout-class frame-class">
<p>This is Content</p>
</div>
Is there a possibility to do so?
I tried the following:
tt_content.stdWrap.innerWrap.cObject = TEXT
tt_content.stdWrap.innerWrap.cObject {
field = frame_class
required = 1
noTrimWrap = |field:frame_class-| |
}
Solution 1:
tt_content.stdWrap.innerWrap.cObject = COA
tt_content.stdWrap.innerWrap.cObject {
10 = TEXT
10.field = layout_class
20 = TEXT
20.field = frame_class
20.wrap = -|
}
Solution 2:
tt_content.stdWrap.innerWrap.cObject = TEXT
tt_content.stdWrap.innerWrap.cObject {
value = {field:layout_class}-{field:frame_class}
stdWrap.insertData = 1
}
Deactivate css_styled_content
Activate fluid_styled_content
Adjust your project's stylesheet to fluid_styled_content classes
Trying to understand the right way to do templating in typo3, I came from typo3 6.2 to typo3 v9.5 and everything is new. I've achieved to use DCE, create a backend layout, and now I'm trying to create a repetitive element to use on multiple pages with different templates for instance.
Comparing with a fresh typo3 installation with the main template provided with typo3, I can see they use a file inside
:
ext/your_template/Resources/Private/Partials/Page/Structure/Footercontent
Then in the template, they render the html file that loads the elements from the home template (I guess).
Here you can see the render
My problem comes when I try to replicate this in my own page. It doesn't render in my page, not even the html base structure.
FooterContent.html inside as I show in this picture
and the render call in my main template like in this picture
Home.html (Template)
<f:section name="Footer">
<f:render partial="Structure/FooterContent" arguments="{_all}" />
</f:section>
FooterContent.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<section class="section footer-section footer-section-content">
<div class="beez_footer">
<div class="beez_footer_top beez_section">
<div class="beez_ft_left">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '5'}" />
</div>
<div class="beez_ft_right">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '6'}" />
</div>
</div>
<div class="beez_footer_middle beez_section">
<div class="beez_ft_left">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '7'}" />
</div>
<div class="beez_ft_middle">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '8'}" />
</div>
<div class="beez_ft_right">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '9'}" />
</div>
</div>
<div class="beez_footer_bottom beez_section">
<div class="beez_ft_left">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '10'}" />
</div>
<div class="beez_ft_right">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: 11}" />
</div>
</div>
</div>
</section>
</html>
setup.typoscript in (ext/your_template/Configuration/Typoscript/):
######################
#### DEPENDENCIES ####
######################
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:fluid_styled_content/Configuration/TypoScript/setup.typoscript">
################
#### HELPER ####
################
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:nubis_theme/Configuration/TypoScript/Helper/DynamicContent.typoscript">
##############
#### PAGE ####
##############
page = PAGE
page {
typeNum = 0
shortcutIcon = EXT:nubis_theme/Resources/Public/Icons/favicon.ico
10 = FLUIDTEMPLATE
10 {
# Template names will be generated automaticly by converting the applied
# backend_layout, there is no explicit mapping nessesary anymore.
#
# BackendLayout Key
# subnavigation_right_2_columns -> SubnavigationRight2Columns.html
#
# Backend Record
# uid: 1 -> 1.html
#
# Database Entry
# value: -1 -> None.html
# value: pagets__subnavigation_right_2_columns -> SubnavigationRight2Columns.html
templateName = TEXT
templateName {
cObject = TEXT
cObject {
data = pagelayout
required = 1
case = uppercamelcase
split {
token = pagets__
cObjNum = 1
1.current = 1
}
}
ifEmpty = Default
}
templateRootPaths {
0 = EXT:nubis_theme/Resources/Private/Templates/Page/
1 = {$page.fluidtemplate.templateRootPath}
}
partialRootPaths {
0 = EXT:nubis_theme/Resources/Private/Partials/Page/
1 = {$page.fluidtemplate.partialRootPath}
}
layoutRootPaths {
0 = EXT:nubis_theme/Resources/Private/Layouts/Page/
1 = {$page.fluidtemplate.layoutRootPath}
}
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = media
}
20 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
20 {
levels = 2
includeSpacer = 1
as = mainnavigation
}
}
}
meta {
viewport = {$page.meta.viewport}
robots = {$page.meta.robots}
apple-mobile-web-app-capable = {$page.meta.apple-mobile-web-app-capable}
description = {$page.meta.description}
description {
override.field = description
}
author = {$page.meta.author}
author {
override.field = author
}
keywords = {$page.meta.keywords}
keywords {
override.field = keywords
}
X-UA-Compatible = {$page.meta.compatible}
X-UA-Compatible {
attribute = http-equiv
}
# OpenGraph Tags
og:title {
attribute = property
field = title
}
og:site_name {
attribute = property
data = TSFE:tmpl|setup|sitetitle
}
og:description = {$page.meta.description}
og:description {
attribute = property
field = description
}
og:image {
attribute = property
stdWrap.cObject = FILES
stdWrap.cObject {
references {
data = levelfield:-1, media, slide
}
maxItems = 1
renderObj = COA
renderObj {
10 = IMG_RESOURCE
10 {
file {
import.data = file:current:uid
treatIdAsReference = 1
width = 1280c
height = 720c
}
stdWrap {
typolink {
parameter.data = TSFE:lastImgResourceInfo|3
returnLast = url
forceAbsoluteUrl = 1
}
}
}
}
}
}
}
includeCSSLibs {
}
includeCSS {
nubis_theme_layout = EXT:nubis_theme/Resources/Public/Css/layout.min.css
}
includeJSLibs {
}
includeJS {
}
includeJSFooterlibs {
}
includeJSFooter {
nubis_theme_scripts = EXT:nubis_theme/Resources/Public/JavaScript/Dist/scripts.js
}
}
################
#### CONFIG ####
################
config {
absRefPrefix = auto
contentObjectExceptionHandler = 0
no_cache = {$config.no_cache}
uniqueLinkVars = 1
pageTitleFirst = 1
linkVars = L
prefixLocalAnchors = {$config.prefixLocalAnchors}
renderCharset = utf-8
metaCharset = utf-8
doctype = html5
removeDefaultJS = {$config.removeDefaultJS}
inlineStyle2TempFile = 1
admPanel = {$config.admPanel}
debug = 0
cache_period = 86400
sendCacheHeaders = {$config.sendCacheHeaders}
intTarget =
extTarget =
disablePrefixComment = 1
index_enable = 1
index_externals = 1
index_metatags = 1
headerComment = {$config.headerComment}
// Disable Image Upscaling
noScaleUp = 1
// Compression and Concatenation of CSS and JS Files
compressJs = 0
compressCss = 0
concatenateJs = 0
concatenateCss = 0
}
Then, inside my website I get only the content I've been able to display from the template.
In other words, everything except the render partial.
I couldn't see any problem related to this and the documentation from typo3 doesn't clarify this.
I must be missing something but I don't know what.
Edit: Added setup.typoscript (I'm using the default setup provided by when installing the theme package from: https://sitepackagebuilder.com)
From the comments the solution should be to add the section to the default page layout file.
By default (from sitepackagebuilder) a layout file is used, so sections defined in a template must be defined in the layout file.
In the default layout file you find only a Section "main" which is rendered.
To add the Footer section, place a RenderViewHelper somewhere in your layout:
<f:render section="Footer" />
If you want to make it optional you can add the attribute optional="true" to the ViewHelper so you dont have to define the Footer Section in every Template if you dont need this.
The structure of a FLUIDTEMPLATE looks like this:
Templates can contain Partials and can have Sections
Partials can contain other Partials
Layouts are enclose the Templates can render Sections and can also contain Partials
If you want to render a footer to your global page, place the footer Partial in your Layout file. If you want a footer depending on the template used, place the footer in a Section of your template and let render the Section in your Layout.
just for clarification of René's answer:
Fluid Templates:
templates - this is the entry into fluid. if you call fluid, you call a template (<f:layout name="layoutname" />). A template can determine a layout; if it does so, the rendering starts with the layout
layouts - they are meant to give a general structure. This can be achieved by inserting different sections from the determining template and/ or from partials.
partials - these are the flexible building blocks your page will be build. everytime you have a block of data which might occur more often, or which is an unit for itself, make a partial from it, so you can reuse it and structure your fluid.
sections can occur in templates and partials as a subblock.
If you insert sections like <f:render section="sectionname" /> the section is expected to be in the current file - except for layouts, they expect their sections in the template.
If you want to insert a section from another file you only can insert sections from a partial: <f:render section="sectionname" partial="partialname" />.
If you ommit the section name you insert the whole partial (<f:render partial="partialname" />)
In general all insertions with f:render transmit no data (fluid variables), except: a layout gets all data known to the determining template, and a section in the template which is inserted from a layout knows all data of the initial template.
For all other insertions you may need to transfer data with the arguments parameter of the f:render viewhelper:
<f:render section="sectionname" arguments="{ind1:'data1', ind2:'data2'}" />
A special case: you can transfer all (localy known) data with arguments="{_all}"
Thanks to René Pflamm and Bernd Wilke for their explanation. Since I came from tpyo3 v6.2, I used mark records there to repeat the same item over multiple templates with the:
LOGO = RECORDS
LOGO.tables = tt_content
LOGO.source = 1
And then in template
<div class="myClass">###LOGO###</div>
This allowed me to get some elements from a folder inside typo3 that matched their id.
I don't know if this can still be used, but I created a simple function
(located at
ext/your_theme/Configuration/Typoscript/Helper/DynamicContent.typoscript)
to use in partials where I call typoscriptObjectPath="lib.dynamicContentFunction" and this allow me to call through data parameters the id of the element I'd like to render. Here's an example and the function:
<f:cObject typoscriptObjectPath="lib.dynamicContentFunction" data="{Uid: '11'}" />
AND
lib.dynamicContentFunction = COA
lib.dynamicContentFunction {
5 = LOAD_REGISTER
5 {
Uid.cObject = TEXT
Uid.cObject {
field = Uid
}
}
20 = CONTENT
20 {
table = tt_content
select {
includeRecordsWithoutDefaultTranslation = 1
orderBy = sorting
where = {#uid}={register:Uid}
where.insertData = 1
pidInList = -1
recursive = 99
}
stdWrap {
dataWrap = {register:wrap}
required = 1
}
}
90 = RESTORE_REGISTER
}
Warning: This may impact your website speed if you have many elements.
Also, I'd like to know what do you guys think. Is there a better way to do this?
Purpose: Render a determinated content element created in typo3 and editable from there where I can call in partials by selecting their id. The function must search if posible from a determinated typo3 page/folder(id) and select the desired content element through data parameters. So this way I can use an editable footer element that will repeat on every page for instance.
I'm starting my "adventure" with tx_news TYPO3 extension. I created the new list template and I see it in flexform on drop down list - that is ok, but how to chose that template using only TypoScript? Is it possible?
Thanks for any help.
I figured out. Here is the solution - if you have in your template, the templateLayout with number 99 (as in tx_news tutorial) <f:if condition="{settings.templateLayout} == 99"> in TypoScript you should use this code to call the 99 layout:
lib.some_news < lib.news
lib.some_news = USER
lib.some_news {
userFunc = tx_extbase_core_bootstrap->run
extensionName = News
pluginName = Pi1
switchableControllerActions.News.1 = list
settings < plugin.tx_news.settings
settings {
categories = 7
templateLayout = 99 # your layout number
limit = 1
detailPid = 22
overrideFlexformSettingsIfEmpty := addToList(detailPid)
startingpoint = 20
list {
media {
image {
maxWidth = 588
maxHeight = 428
width = 588c
height = 428c
}
}
}
}
}
Just 3 Steps.
1) Copy tepmlate from EXT folder to web site template and add in typoscript
plugin.tx_news {
view {
# Additional template paths
templateRootPaths.110 = youPath/Templates/
# Additional partial paths
partialRootPaths.110 = youPath/Partials/
# Different template for pagination
widget.Tx_News_ViewHelpers_Widget_PaginateViewHelper.templateRootPath = youPath/Templates/
}
}
2) Copy Partials inside your new "news" template. Like copy Partial/List to Partials/Latest (for exampl)
3) Now you shood write rule fore template "youPath/Templates/List.html" or/and the same fore Detail.html (if need)
<!-- Strat template -->
<f:section name="content">
<f:if condition="{settings.templateLayout}"> <!-- if we heve Layout than include our new partitial -->
<f:then>
<f:render partial="{settings.templateLayout}/List" arguments="{news: news, settings:settings}"/>
</f:then>
<f:else>
<!-- ... default Template-->
That's all) Good luck
I do get following Error when using your script.
No value found for key "TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper->switchExpression", thus the key cannot be removed.
I've checked the manual as well (http://docs.typo3.org/typo3cms/extensions/news/Main/Tutorial/IntegrationWithTs/Index.html) and also this snipped seems not to work properly.
This possibly might fix the issue: https://forge.typo3.org/issues/59255
I wonder if it is possible to insert a locallang value into my typoscript wrap / stdWrap object:
I have:
singleView {
related.wrap = <div class="related">Related items: |</div>
}
What I need is something like that:
singleView {
related.wrap = <div class="related">{LLL:related_items}:|</div>
}
EDIT:
What I am looking for is an TS equivalent for $this->pi_getLL (which works fine).
In our case, we would be replacing values in our extension with
$this->cObj->stdWrap($item, $this->conf['singleView.']['related']);
locallang.xml in extensions /pi1 directory:
<languageKey index="default" type="array">
<label index="related_items">Related items: </label>
</languageKey>
singleView {
related.dataWrap = <div class="related">{LLL:EXT:myextensionkey/pi1/locallang.xml:related_items}:|</div>
}
Of course related_items must be a valid locallang key.
Edit: Do not use wrap with insertData here, because insertData is then run on the whole content, including the user input. If somebody uses {DB:be_users|0|password} inside the content you are wrapping, he can just see the password (hash) of the backend user with uid 0.
Building on the answer of pgampe here, sadly I don't have enough reputation to do it in a comment.
For easier use, do something like this:
constants:
extension.key = myextensionkey
LLL = LLL:EXT:{$extension.key}/Resources/Private/Language/locallang.xlf
and in your typoscript:
singleView {
related.dataWrap = <div class="related">{{$LLL}:related_items}:|</div>
}
I tried to create a typo3 template with a special div-tag.
The editors should have the possibility to add images to the page-element. The goal should be the following code:
<div id="special_div_tag_in_template">
<img src="first_image_from_editor_in_page_element.png" />
<img src="second_image_from_editor_in_page_element.png" />
<img src="third_image_from_editor_in_page_element.png" />
</div>
Is there a possibility to create a custom element preset / form field?
I hope some one has a hint how to solve with this problem.
Thanks, Andreas
You can use the media field of the page properties:
lib.headerImage = COA
lib.headerImage {
wrap = <div id="special_div_tag_in_template">|</div>
10 = IMAGE
10 {
file {
import = uploads/media/
import {
field = media
listNum = 0
}
// set the dimensions if you want
height = 200
width = 100m
}
}
// create a copy and select 2nd image
20 < .10
20.file.import.listNum = 1
// create a copy and select 3rd image
30 < .10
30.file.import.listNum = 2
}
Take a look at the TYPO3 Wiki for more examples of header images.
A different approach would be to create DS/TO in TemplaVoila and insert this as a flexible content element (FCE)