Give renderObj = IMAGE a class - typo3

I want to use a lazy-loader for my images. Therefore I found a JS which seems pretty comfortable. Nevertheless, my images need a class="lazy" so that the JS knows which images it should affect.
The problem is, that I'm using a dynamically generated page with images which are stored in the media relation of each page. Idk if you guys understood what i meant :D
But anyway, that's not the point. The point is, I need a way to give the rendered images a class by TypoScript. I'm looking for something like this:
[...]
renderObj = IMAGE
renderObj {
file.import.data = file:current:publicUrl
altText.data = file:current:title
addClass = lazy
}
[...]

You can use params for this:
[...]
renderObj = IMAGE
renderObj {
file.import.data = file:current:publicUrl
altText.data = file:current:title
params = class="lazy"
}
[...]

Related

HMENU/GMENU render pages.media field

I am migrating typoscript from TYPO3 6.2 ELTS to 7.x ELTS.
Following code works in 6.2 thanks to activateContentAdapter which is removed in TYPO3 7. https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/7.2/Breaking-66034-DropContentAdapter.html
Is that possible to still use HMENU/GMENU or should I rewrite it totally other way?
lib.navigation.socialmedia = HMENU
lib.navigation.socialmedia{
wrap = <ul>|</ul>
special = directory
special.value = 123
1 = GMENU
1{
NO{
wrap = <li class="first">|</li>|*|<li class="middle">|</li>|*|<li class="last">|</li>
altImgResource.import = uploads/media/
altImgResource.import.field = media
altImgResource.import.listNum = 0
ATagTitle.field = subtitle // title
}
}
}
you still could use GMENU but you need to change the filehandling. As mentioned files are no longer just copied to uploads/media/ but there is a file-handle (sys_filerecord) whose uid is used everywhere.
First substitution: treatIdAsReference
This is a usage for rendering an icon of the first media entry in a text menu (TMENUITEM) before the text (1).
The rendering is inside of the FILESobject which represents an (possible) array. SO it might be a little bit complicated to insert it into an IMGRESOURCEobject (2).
if you just want the resource adapt the renderObj, as this example renders the image (cropped) and generates an <img>tag.
NO.stdWrap.prepend = FILES
NO.stdWrap.prepend {
references {
table = pages
uid.data = current:originalUid // current: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
params = class="menu-img"
stdWrap.typolink.parameter.field = uid
}
maxItems = 1
}
(1) with the options of CSS3 and HTML5 and the preferred way of accessibility you have multiple ways to use a clean text menu without 'hiding' text in graphics.
(2) you might use altImgResource.cObject = FILES and render an IMGRESOURCE instead of an IMAGE.
meanwhile (since TYPO3 9) you have menu_processors and you would render the menu with fluid, where you 'navigate' through the pagetree with all properties of each page, including images.

Typoscript 9.5 render FILES Object like Contentelement

i get via CONTENT an Element from the page and want to render the image from this like all other images in the page.
i have installed sms for responsive images but when i render this image via typoscript an normal <img> will be outputtet.
how must i change my typoscript to render like in the partial file Media/Rendering/Image?
20 = FILES
20{
references {
table = tt_content
fieldName = image
uid.data = field:uid
}
begin = 0
maxItems = 1
renderObj = IMAGE
renderObj {
file.import.data = file:current:publicUrl
file.width = 1920c
file.treatIdAsReference = 1
stdWrap.outerWrap = |
}
}
thank you very much!
As the example you mention is rendered in Fluid, I'd suggest to use Fluid as well. The ViewHelper for responsive images is used in Fluid.
Try to get away from rendering via TypoScript and use Fluid templates.

typo3 add image resource as background

I'm totally new to typo3, I need to make a div with background from a specific page. For example on home page, I would like to use a media resource from page id 20.
I got something like that
page.20 = TEMPLATE
page.20.template = FILE
page.20.template.file = fileadmin/refood/layouts/home.html
page.20.workOnSubpart = DOCUMENT
page.20.subparts{
BOX1 < styles.content.get
BOX1.select.where = colPos=1
BOX1.wrap = <div class="offers"><div class="home-box-desc"></div><div class="home-box-desc">|</div><div class="meta-square-green"></div></div>
BOX1.stdWrap.typolink.parameter = 14 _self home-box }
I tried to use something like that
references {
table = pages
uid.data = 20
fieldName = media
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:publicUrl
altText.data = file:current:title
wrap = <div class="offers">|</div>
}
BOX1.wrap = <div class="home-box-desc" style="background:url(|)"></div>
Into a subpart part, but nothing happens. How should I make it ?

Pass content from TypoScript to fluid template in TYPO3 7.6

I would like to read content via TypoScript and render it through a custom Fluid template. Without css_styled_content or fluid_styled_content.
temp.test = CONTENT
temp.test {
table = tt_content
select.languageField = 1
select.selectFields = bodytext,image,header,header_link
select.where = colPos = 1
renderObj = FLUIDTEMPLATE
renderObj {
file = path/to/Teaser.html
}
}
This works with strings, say
<f:debug>{data.header}</f:debug>
But not with
<f:debug>{data.image}</f:debug>
returning only the number of images.
Now, in a classic TypoScript RenderObj (maybe a COA), you would have added something like
10 = FILES
10 {
required = 1
references {
table = tt_content
fieldName = image
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:originalUid // file:current:uid
file.width=654
file.height = 327c
//stdWrap.typolink.parameter.data = file:current:link
altText.data = file:current:description // file:current:title // file:current:alternative
}
}
While nowadays, we want to do that in the Fluid template. But how to resolve the FAL image to pass it to the fluid template?
You should be able to use the TYPO3\CMS\Frontend\DataProcessing\FilesProcessor data processor that will fetch the file data for you so you can access it with {files} in your template.
renderObj = FLUIDTEMPLATE
renderObj {
file = path/to/Teaser.html
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10.references.fieldName = image
}
}
The main problem is all image information are stored in a different table called "sys_file_reference". Selecting "tt_content.image" will not help you here. There are 2 ways to solve this problem, IMHO.
1) Create your own viewhelper. This VH can be utilized to query the images as it is done here.
2) Create a small TypoScript lib and use it as f:cObject in your fluid template. This is described here.
I'm not saying that my solution is the best one. But it's the only one I'm aware of. Looking forward seeing better solutions ;)

Is it possible to write a specific query in typoscript

my question may seem trivial, sorry if it is! I am currently learning typo3 and typoscript. I want to create a template with a dynamic background image. This image is stored in a directory. I would like to get the image name from the table tt_content. However, the way this works confuses me a bit and i don't know if my take on it is the right one.
The code looks like this:
20 = CONTENT
20.table = tt_content
20.select{
where = pid = 79
}
20.headerImagePath = COA
20.headerImagePath {
10 = TEXT
10.stdWrap.field = image
10.stdWrap.wrap = <div class="background-media" style="background-image: url('|'); background-repeat: no-repeat; background-size: cover; background-attachment: fixed; background-position: 50%;" data-start="background-position:50% 50%"
data-70-top-bottom="background-position:50% 70%">
</div>
}
I'd like to store the information about the image (the div part in the code) in a variable and put it into my template. The template part of my code looks like this:
<f:format.raw>{headerimage}</f:format.raw>
or
<f:cObject typoscriptObjectPath="headerimage" />
So my question would be, is the way i am selecting things from the database and storing into a variable correct and is the way i am calling them in the template correct? If the way above should work but i have some little errors, is it good practice or should i do things differently?
Kind Regards
Adi
your snippet will not work, because your structure is very wrong.
On
20.headerImagePath = COA
you try to create a new CONTENT OBJECT ARRAY on a CONTENT OBJECT.
20 = CONTENT
This will not work.
But the CONTENT Object has a property called renderObj.
Look at following example:
UNTESTED
Try it like this:
lib.headerImagePath = CONTENT
lib.headerImagePath {
# first call the content you need
table = tt_content
select {
# Add your colPos
# In this example i store my header image in colpos 9
where = colPos = 9
# PID from current field or define your own
# pidInList = 123
pidInList.field = uid
languageField = sys_language_uid
}
renderObj = COA
renderObj {
# FILES object was introduced in TYPO3 6.x
10 = FILES
10 {
# Set a reference to let the file object know, where we will get the images
references {
table = tt_content
uid.field = uid
fieldName = image
}
# make sure we only get the first image in set
maxItems = 1
renderObj = COA
renderObj {
# We only need the url and not the complete image. So we need a IMG_RESOURCE and not an IMAGE Object
10 = IMG_RESOURCE
10 {
stdWrap {
wrap = <div class="background-media" style="background-image: url('|'); background-repeat: no-repeat; background-size: cover; background-attachment: fixed; background-position: 50%;" data-start="background-position:50% 50%" data-70-top-bottom="background-position:50% 70%"></div>
required = 1
}
# Import file from current object
# and treat the id as a reference (TYPO3 File Abstraction Layer)
file {
import.data = file:current:uid
treatIdAsReference = 1
}
}
}
}
}
}
Also look at this examples:
Here they get the header image directly from the MEDIA Element in the page properties:
http://wiki.typo3.org/TypoScript_Header_Image
to get header image as backgound us,its working also in multilanguage work with typo 6.x
page.cssInline {
10 = FILES
10 {
references.data = levelmedia:-1, slide
references.listNum = 0
renderObj = TEXT
renderObj.data = file:current:publicUrl
renderObj.wrap (
.title-1 {
background-image: url(../|) !important;
}
)
}
}
thanks to http://www.derhansen.de/2013/02/using-fal-media-in-typo3-60-for-inline.html