How to use lib.* Variables the correct way in TypoScript - typo3

this is my first submission.
I want a specific image as Background in my Typo3 Template. I want to parse the needed Image from a reference in the Page. Below Code I copied from another website and it seems correct.
lib.headerimage = IMAGE
lib.headerimage {
file {
import.data = levelmedia:-1, slide
treatIdAsReference = 1
import.listNum = 0
}}
The Problem now is, I want the lib.headerimage.FILELINK to be in my following code and I can't figure out how to use lib.VARIABLES
In a later point I parse this:
page.headerData {
10 = TEXT
10.value = div#header { background-image: url('lib.headerimage.file.value');}
10.wrap = <style type="text/css">|</style>
}
With our without $ it doesn't parse anything. I just started using typoscript 3 days ago again. My last experiences were years back.
Please , there must be an easy way to do this. :/

It looks like you search a way to concat strings. Assumed the first part is correct (As I am not familiar with the IMAGE Object) you can concat the strings like this:
page.headerData {
10 = COA
10 {
10 = TEXT
10.value = <style type="text/css">div#header { background-image: url('
20 < lib.headerimage
30 = TEXT
30.value = ');}</style>
}
}

lib.headerImageText = COA
lib.headerImageText {
10 = IMG_RESOURCE
10.file.treatIdAsReference = 1
10.file.import {
cObject = TEXT
cObject.value = dummy.gif
cObject.override {
required = 1
data = levelmedia: -1, slide
listNum = 0
}
}
}
AND
page.headerData {
10 = COA
10 {
10 = TEXT
10.value = <style type="text/css">div#header { background-image: url('
20 < lib.headerImageText
30 = TEXT
30.value = ');}</style>
}
}
Fixed my problem ;) now the div#header has the correct background-url defined in the typo3 backend.

Related

TYPO3 10 <f:cObject/> does NOT render first content-element from tt_content table after clearing cache

I am currently facing the issue, that when I fetch content from a specific page via typoscript, I only get the full content after the second pageload if I have deleted all caches before. The first content element is not rendered at all (seems to be ignored).
Here is my Typoscript:
lib.dynamicContent = COA
lib.dynamicContent {
5 = LOAD_REGISTER
5 {
colPos.cObject = TEXT
colPos.cObject {
field = colPos
ifEmpty.cObject = TEXT
ifEmpty.cObject {
value.current = 1
ifEmpty = 0
}
}
pageUid.cObject = TEXT
pageUid.cObject {
field = pageUid
ifEmpty.data = TSFE:id
}
contentFromPid.cObject = TEXT
contentFromPid.cObject {
data = DB:pages:{register:pageUid}:content_from_pid
data.insertData = 1
}
wrap.cObject = TEXT
wrap.cObject {
field = wrap
}
}
20 = CONTENT
20 {
table = tt_content
select {
includeRecordsWithoutDefaultTranslation = 1
orderBy = sorting
where = {#colPos}={register:colPos}
where.insertData = 1
pidInList.data = register:pageUid
pidInList.override.data = register:contentFromPid
}
stdWrap {
dataWrap = {register:wrap}
required = 1
}
}
90 = RESTORE_REGISTER
}
This is how I render the content in fluid:
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{pageUid: '41', colPos: '1'}" />
The output from the first content element after clearing the cache is on the first pageload: <div />. When I reload the page, I get the full content from the page.
I already checked the database queries which are executed, but they are always the same and return the correct results.
System:
TYPO3 10.4.8
PHP 7.3
You should remove the stdWrap part, which contains a wrap, that should be created via plain HTML in your Fluid template instead.
Im not 100% sure, but I guess the required check within that stdWrap section disables the content as well, since it might be checked before the actual content has been rendered.

Add image to menu/sitemap element in TYPO3

I am using TYPO3 4.7 (Upgrading is not an option). Can I customize the Menu/Sitemap element to include the first image on each linked page?
So In this case I'd be using:
tt_content.menu.20.1.1.NO
First of all you really should update the site as there are a lot security issues which can do harm to your/your customer's website.
Back to your question: Of course you can render any content inside a menu as well!
lib.menu = HMENU
lib.menu {
wrap = <ul>|</ul>
1 = TMENU
1.NO {
wrapItemAndSub = <li>|</li>
after.cObject = CONTENT
after.cObject {
table = tt_content
select {
pidInList.field = uid
}
renderObj = COA
renderObj {
10 = TEXT
10.field = header
10.htmlSpecialChars = 1
20 = TEXT
20 {
field = image
split {
token = ,
cObjNum = 1
1 {
10 = IMAGE
10 {
file {
import=uploads/pics/
import.current = 1
width = 170
height = 100
}
}
}
}
}
}
}
}
}
tt_content.menu.20.1.1.NO < lib.menu.1.NO
To be honest: the part with the image is untested as I don't have any non-FAL (since 6.0) installation anymore where I could test it.

how to use load_register in typo3

I begin with TYPO3 and I try to work with LOAD_REGISTER.
I've read multiple examples on the net and I want to try some tests but I'm not able to output the data from LOAD_REGISTER-variables.
Here's my code :
page = PAGE
page {
count = LOAD_REGISTER
count {
nbblocks.cObject = TEXT
nbblocks.cObject {
data = patate
}
}
10 = TEXT
10.value = register:nbblocks
10.wrap = <h1>|</h1>
}
Page only shows "register:nbblocks", which must be a basic mistake.
Thanks in advance for the help :-)
There are several problems with your code.
Firstly, the page.count = LOAD_REGISTER content object is not run before page.10 = TEXT, which means that the register you're creating is does not exist where you want to use it. This can be fixed by renaming page.count to page.10 and page.10 to page.20.
Secondly, you should set the value-key on nnblocks.cObject instead of the data-key.
Thirdly, you need to wrap registers used in the value-property of the TEXT-object in curly brackets ({register:nbblocks}), and lastly, you need to set stdWrap.insertData = 1 on the TEXT-object.
All in all, this gives you the following code:
page = PAGE
page {
10 = LOAD_REGISTER
10 {
nbblocks.cObject = TEXT
nbblocks.cObject {
value = patate
}
}
20 = TEXT
20.value = {register:nbblocks}
20.wrap = <h1>|</h1>
20.stdWrap.insertData = 1
}

Subpage Links with image and text

I try to implement a page which contains images to certain subpages. For each subpage, I have a seperate image. I want to display for each subpage the appropriate image "galerie_XX.png" an show the name of the subpage above the image. So far I got:
galerielabel = HMENU
galerielabel.special = directory
galerielabel{
1 = TMENU
1.NO.stdWrap{
wrap = <img src="fileadmin/templates/images/galerie/galerie_|.png" />
}
}
The Subpages are year names, like 2012, 2013... This script shows me the required images as a link.
My question is, how can I add the name of the subpages above the image?
Thank you in advance.
I suggest a different approach.
You can add images in the page properties.
Then, your menu could be like this:
lib.menu = COA
lib.menu.10 = HMENU
lib.menu.10 {
10 = HMENU
10.1 = TMENU
10.1.NO.doNotShowLink = 1 #will remove the link altogether
10.1.NO.before.cObject = COA
10.1.NO.before.cObject {
10 = TEXT
10.field = title #title of the page, change to any field you like
20 = IMAGE
20.file.import = uploads/media/ #4.x style
20.file.import.field = media
20.file.import.listNum = 0 #use first image referenced
20.width = 200 #set to imagesize of your liking
30 = TEXT
30.value = Do what you like here
}
}
Untested: the title of the page should be prepended
galerielabel = HMENU
galerielabel.special = directory
galerielabel{
1 = TMENU
1.NO.stdWrap{
# Prepend with page.title
prepend = TEXT
prepend {
field = title
htmlSpecialChars = 1
}
wrap = <img src="fileadmin/templates/images/galerie/galerie_|.png" />
}
}

Typoscript IMAGE object: disable height/width attributes

Is there any way to prevent typo3/typoscript IMAGE object from adding the dimension attributes (height and width) to the generated image tag?
UPDATE (Thanks to cascaval)!
The solution is to use IMG_RESOURCE instead of IMAGE. It apparently has less bells an whistles but gives you complete control of the the generated image tag.
10 = IMG_RESOURCE
10.file.import = uploads/tx_templavoila/
10.file.import.current = 1
10.file.import.listNum = 0
10.stdWrap.required = 1
10.stdWrap.wrap (
<img src="|" />
)
Note: This is for use with Templavoila.
No but you can use IMG_RESOURCE object instead and wrap the resulting image path so that you get a HTML tag you want. Example:
temp.image_test = IMG_RESOURCE
temp.image_test {
stdWrap.wrap = <img src="|" />
file = GIFBUILDER
file {
format = jpg
quality = 90
maxWidth = 9999
maxHeight = 9999
XY = [10.w],[10.h]
10 = IMAGE
10.file {
import = uploads/pics/
import.field = image
import.listNum = 0
}
20 = SCALE
20 {
width = 200
}
}
}
Wrong! It also works with IMAGE:
10 = IMAGE
10 {
file = path/to/image.file
stdWrap.replacement {
10 {
search = # width="[0-9]*?"#i
replace =
useRegExp = 1
}
20 {
search = # height="[0-9]*?"#i
replace =
useRegExp = 1
}
}
}