I want to create a typolink from the current page but with other name and some additional GET parameter. E.g.
My custom name
This is my code which only prints out a text with MyCustomName.
lib.tsfooter >
lib.tsfooter = COA
lib.tsfooter {
10 = TEXT
10.value (
<!-- some HTML code-->
)
20 = TEXT
20.value = MyCustomName
20.stdWrap.typolink {
data = TSFE:id
addQueryString = 1
addQueryString.method = get
additionalParams = &myCustomParameter=1
}
}
What I'm doing wrong?
lib.tsfooter >
lib.tsfooter = COA
lib.tsfooter {
10 = TEXT
10.value (
<!-- some HTML code-->
)
20 = TEXT
20.value = MyCustomName
# you do not need "stdWrap" as pgampe mentioned, but it will work even with stdWrap
20.stdWrap.typolink {
# parameter was missing
parameter.data = TSFE:id
addQueryString = 1
addQueryString.method = get
additionalParams = &myCustomParameter=1
}
}
Related
I would like to maintain the hreflang for pages in Typo3 7.6.19.
This is not possible automatically, because the pages are external and different.
With Yoast-SEO this possibility (at least in my version) does not come along.
It is an old Typo3 version, so I cannot use the extension bgm_hreflang from the TER.
Anyone an idea?
The structure of the hreflang meta is known.
https://developers.google.com/search/docs/advanced/crawling/localized-versions
I think I found out. I checked at which position the hreflang was generated:
headerData {
10 = HMENU
10 {
special = language
special.value = 0,1
special.normalWhenNoLanguage = 0
1 = TMENU
1 {
NO = 1
NO {
stdWrap.cObject = TEXT
stdWrap.cObject {
value = de || en
}
linkWrap = <link rel="alternate" hreflang="|
doNotLinkIt = 1
after.cObject = TEXT
after.cObject {
stdWrap {
wrap = " href="|" />
typolink {
parameter.data = TSFE:id
#page:uid
additionalParams = &L=0 || &L=1
returnLast = url
forceAbsoluteUrl = 1
addQueryString = 1
addQueryString.method = GET
addQueryString.exclude = gclid,L,id,cHash,no_cache,backPid
}
}
}
}
CUR = 1
CUR.doNotShowLink = 1
# No Translation
USERDEF1 = 1
USERDEF1.doNotShowLink = 1
USERDEF2 < .CUR
}
}
}
And then overwritten by the template extension per page:
page.headerData.10 >
page.headerData.10 = TEXT
page.headerData.10.value (
(...)
<link rel="alternate" href="https://example.com/" hreflang="x-default" />
)
Of course, it would be nicer if the editor would only have to enter urls as HTML code, but for the moment it fits.
For the generation of the canonical tag by typoscript, I need to check if the current page is translated. If not, the canonical needs to point to the url in default language.
How can I check if current page is translated by typoscript?
Language handling in my typoscript config:
sys_language_overlay = 1
sys_language_mode = content_fallback
If anyone is interested, I have worked out a solution to my task: Render the canonical url in default language if there is no translation for the current page (content_fallback)
page.headerData.10 = COA
page.headerData.10 {
10 = LOAD_REGISTER
10.isPageTranslated.cObject = CONTENT
10.isPageTranslated.cObject {
table = pages
select {
selectFields = plo.sys_language_uid
pidInList = {$config.rootPid}
join = pages_language_overlay plo ON plo.pid = pages.uid
where = plo.pid = ###pid### AND plo.sys_language_uid = ###lang### AND plo.deleted = 0 AND plo.hidden = 0
markers {
pid.data = page:uid
lang.data = page:sys_language_uid
}
}
renderObj = TEXT
# translation available
renderObj {
wrap = <link rel="canonical" href="|">
typolink {
parameter.data = TSFE:id
returnLast = url
}
append = TEXT
append.value (
)
}
}
20 = TEXT
20 {
data = register:isPageTranslated
ifEmpty {
# no translation available
wrap = <link rel="canonical" href="|">
typolink {
parameter.data = TSFE:id
additionalParams = &L=0
returnLast = url
}
append = TEXT
append.value (
)
}
}
}
I have a problem with accessing content in a content object in TYPO3:
Running in TYPO3 8.7.11, I have a page with a Content Element "Image" and I've loaded a single image inside. I want to get an output like this:
<section class="foo" style="background-image:url('fileadmin/foo.png')">
<h2>[image title]</h2>
<p>[image description]</p>
</section>
I got the part with the image title and description working, but I cannot get the image filename for the background image running!
My current Typoscript looks like this:
(edited after Thomas answer, but still not running)
lib.teaser = CONTENT
lib.teaser {
table = tt_content
select.where = colPos = {$teaser_column}
languageField = sys_language_uid
renderObj = COA
renderObj {
# Attempt 1 (regarding the answer of Thomas Löffler)
# this doesn't work and result in an empty URL
#
# 10 {
# references {
# uid.data = uid
# table = tt_content
# fieldName = media
# }
#
# begin = 0
# maxItems = 1
#
# renderObj = IMG_RESOURCE
# renderObj {
# file.import.data = file:current:publicUrl
# }
# stdWrap.wrap = <section class="teaser" style="background-image:url('|');">
# }
# Attempt 2 (regarding the answer of Bernd Wilke πφ)
# this doesn't work and result in an empty URL
10 = FILES
10 {
references {
uid.data = uid
table = tt_content
fieldName = media
}
# a) did you mean that I want to replace
# my renderObj and use a TEXT object instead?
renderObj = TEXT
renderObj {
data = file:current:publicUrl
}
# b) ... or did you mean that I want to provide
# an IMG_RESOURCE and inside of that I want to
# provide a renderObj = TEXT?
#
# renderObj = IMG_RESOURCE
# renderObj {
# listNum = 0
# override.field = media
# renderObj = TEXT
# renderObj.data = file:current:publicUrl
# }
stdWrap.wrap = <section class="teaser" style="background-image:url('|');">
}
20 = TEXT
20.field = header
20.wrap = <h2 class="hide-text">|</h2>
30 = TEXT
30.field = bodytext
30.wrap = <p>|</p>
90 = TEXT
90.value = </section>
}
}
# ...
# edit: added after Thomas answer below
page {
10 = FLUIDTEMPLATE
10 {
format = html
file = {$root}/Templates/{$template}/Layouts/{$main_layout}.html
layoutRootPath = {$root}/Templates/{$template}/Layouts
partialRootPath = {$root}/Templates/{$template}/Partials
variables {
teaser < lib.teaser
# ... some other variables ...
}
# load templates for sections, otherwise Typo3 won't find your sections
file.stdWrap.cObject = CASE
file.stdWrap.cObject {
key.data = levelfield:-1, backend_layout_next_level, slide
key.override.field = backend_layout
default = TEXT
default.value = {$root}/Templates/{$template}/Templates/Main.html
}
}
}
Currently resulting in this HTML code:
<section class="teaser" style="background-image:url('');">
<h2 class="hide-text">Get our latest products:</h2>
<p></p>
</section>
You use fluid_styled_content, don't you? Why not using FLUIDTEMPLATE and DataProcessing? There you get all the content data in a nice array and you are able to build your HTML like you want.
See https://usetypo3.com/custom-fsc-element.html for a small start.
Here the documentation for DataProcessing: https://docs.typo3.org/typo3cms/TyposcriptReference/8.7/ContentObjects/Fluidtemplate/#dataprocessing
I can't try it but I would do it like this:
10 = FILES
10 {
references {
uid.data = uid
table = tt_content
fieldName = media
}
begin = 0
maxItems = 1
renderObj = IMG_RESOURCE
renderObj {
file.import.data = file:current:publicUrl
}
stdWrap.wrap = <section class="teaser" style="background-image:url('|');">
}
Example: https://docs.typo3.org/typo3cms/TyposcriptReference/8.7/ContentObjects/Files/Index.html#usage-with-references
you have all the parts together, you just mixed them up.
renderObj = IMG_RESOURCE
renderObj {
file.import.data = file:current:publicUrl
listNum = 0
override.field = media
file.treatIdAsReference = 1
}
IMG_RESOURCE would be the correct object, but you do not build it up correctly:
file.import.data = file:current:publicUrl: where the filename is expected you provide the full path to the image. Wait!? 'the full path to the image'? wasn't it what you want to achive?
renderObj = TEXT
renderObj.data = file:current:publicUrl
If you use 'treatIdAsReference = 1' you need to provide an UId (of a sys_file) and no name
10 = FILES
10 {
references {
// this line should not be neccessary as the current context identifies the record
#uid.data = uid
table = tt_content
fieldName = media
}
// we only can handle one image:
maxItems = 1
// if we want no processing of the image:
renderObj = TEXT
renderObj {
data = file:current:publicUrl
}
// maybe a processing is necessary
// (always deliver smallest image possible)
#renderObj = IMG_RESOURCE
#renderObj {
# file {
# import.data = file:current:uid
# treatIdAsReference = 1
# width = 500c
# height = 200c
# }
#}
stdWrap.wrap = <section class="teaser" style="background-image:url('|');">
}
If this does not work you have a general problem extracting the files from your tt_content elements.
Maybe your fieldname is not media?
Inspect your database:
SELECT fieldname
FROM sys_file_reference
WHERE tablenames = 'tt_content'
AND uid_foreign = <tt_content_record-uid>
I just inspected one installation of mine and found: the fieldname is assets.
I want to render all pages into the template to make a onepager
I try this:
page.20 = TEMPLATE
page.20.template = FILE
page.20.template.file = fileadmin/design/index.html
page.20.marks{
lib.sectionContent = HMENU
lib.sectionContent {
1 = TMENU
1 {
NO = 1
NO {
doNotLinkIt = 1
stdWrap >
stdWrap {
cObject = COA
cObject {
if.value = 4
if.equals.field = doktype
if.negate = 1
10 < temp.titleSectionId
10.wrap = <section id="|">
20 = CONTENT
20 {
table = tt_content
select {
pidInList.field = uid
}
wrap = <div class="container">|</div>
renderObj < tt_content
}
30 = TEXT
30 {
wrap = </section>
}
}
}
}
}
}
LANGMENU < temp.langMenu
In the Template File I have a section ###CONTENT###
And I want that all contents were printed there. How would that be possible?
You have a nesting error.
Your nesting currently looks like this (verify with the object browser):
page.20.marks.lib.sectionContent ...
However the the TEMPLATE object at page.20 checks only for keys in .marks.* and expects a valid content object (cObject) configuration there. However the valid key lib has no cObject set.
What you really try to do is this:
# prepare configuration for content
lib.sectionContent = HMENU
lib.sectionContent {
1 = TMENU
1 {
NO = 1
NO {
doNotLinkIt = 1
stdWrap >
stdWrap {
cObject = COA
cObject {
if.value = 4
if.equals.field = doktype
if.negate = 1
10 < temp.titleSectionId
10.wrap = <section id="|">
20 = CONTENT
20 {
table = tt_content
select {
pidInList.field = uid
}
wrap = <div class="container">|</div>
renderObj < tt_content
}
30 = TEXT
30 {
wrap = </section>
}
}
}
}
}
}
# initialize configuration for the default page object
page.20 = TEMPLATE
page.20.template = FILE
page.20.template.file = fileadmin/design/index.html
page.20.marks{
# copy the configuration from above to the right place
CONTENT < lib.sectionContent
# I really hope that you prepared temp.langMenu beforehand
LANGMENU < temp.langMenu
# close block for page.20.marks
}
I have a problem with marking a link in a Stiemap with dateUntil. Here is my typoscript:
tt_content.menu.20.1 >
tt_content.menu.20.1 < tt_content.menu.20.7
tt_content.menu.20.1.1.wrap = <div class="menu_list_sitemap">|</div>
tt_content.menu.20.1.1.NO {
ATagBeforeWrap = 0
doNotLinkIt = 1
stdWrap.htmlSpecialChars = 0
stdWrap.cObject = COA
stdWrap.cObject {
# Untertitel verlinken
10 = TEXT
10 {
field = subtitle
wrap = |
stdWrap.cObject = COA
stdWrap.cObject {
20 = IMAGE
20.file.import.field = media
20.file.import = uploads/media/
20.file.import.listNum = 0
20.wrap = |
30 = TEXT
30.field = title
30.wrap = <div class="txt">|</div>
40 = TEXT
40.if.isPositive.dataWrap = {field:newUntil}-{date:U}
40.wrap = <div class="txt2">|</div>
40.value = NEW
}
typolink.parameter.field = uid
}
}
}
The result is, that the new entries will get an additional div-container with class="txt2". Wokrs fine so far. :-) Here the generated HTML:
<li>
<a href="link-to-my-page">
<img width="22" height="22" alt="" src="my-image.png">
<div class="txt">My-Text</div>
<div class="txt2">NEW</div>
</a>
</li>
But now I need to add a "class='new'" to the Link or optional to a surrounding div-container (not my idea, really). I tried now for some hours to find a solution, but nothing worked.
Any suggestions?
i guess ATagParams would do the job. Use if to add only if needed
tt_content.menu.20.1 >
tt_content.menu.20.1 < tt_content.menu.20.7
tt_content.menu.20.1.1.wrap = <div class="menu_list_sitemap">|</div>
tt_content.menu.20.1.1.NO {
ATagBeforeWrap = 0
doNotLinkIt = 1
stdWrap.htmlSpecialChars = 0
stdWrap.cObject = COA
stdWrap.cObject {
# Untertitel verlinken
10 = TEXT
10 {
field = subtitle
wrap = |
### snip ###
typolink.parameter.field = uid
typolink.ATagParams = class="new"
typolink.ATagParams.if.isPositive.dataWrap = {field:newUntil}-{date:U}
}
}
}