How to wrap image with div in typo3? - typo3

To remove default wrap around image, i have used this template code:
tt_content.image.20.rendering.noWraps {
imageRowStdWrap.dataWrap = |
noRowsStdWrap.wrap = |
oneImageStdWrap.dataWrap = |
imgTagStdWrap.wrap = |
editIconsStdWrap.wrap = |
caption.wrap = |
}
# Set this as active rendering method
tt_content.image.20.renderMethod = noWraps
I want to override it above codes for a specific section.
Here is my code to do so:
SCREENSHOTS<styles.content.get
SCREENSHOTS.select.where = colPos = 9
SCREENSHOTS.renderObj.dataWrap = <div class="screen">|</div>
It doesn't work. How to do it?

According to the documentation for the CONTENT object:
Since in the above example .renderObj is not set explicitly, TYPO3 will automatically set 1.renderObj < tt_content, so that renderObj will reference the TypoScript configuration of tt_content. The according TypoScript configuration will be copied to renderObj.
Since you declare SCREENSHOTS.renderObj.dataWrap = <div class="screen">|</div> you properly wont have any configuration automatically copied to your renderObj.
If I understand your goal correct then you wish to remove all wraps around 'image only' content element and wrap it all in one div tag <div class="screen">|</div>. The following is untested but should work if your provided first code blocked worked for all your 'image only' content elements.
# Create a new renderMethod named 'noWraps' which can be used across the whole system
tt_content.image.20.rendering.noWraps {
imageRowStdWrap.dataWrap = |
noRowsStdWrap.wrap = |
oneImageStdWrap.dataWrap = |
imgTagStdWrap.wrap = |
editIconsStdWrap.wrap = |
caption.wrap = |
}
SCREENSHOTS < styles.content.get
SCREENSHOTS {
select.where = colPos = 9
renderObj < tt_content
renderObj {
# Set renderMethod to 'noWraps' only for this section
image.20.renderMethod = noWraps
# Change the default wrapping around the content element but only if it's a 'image only' contant element
stdWrap.innerWrap >
stdWrap.innerWrap.cObject = CASE
stdWrap.innerWrap.cObject {
key.field = CType
default < tt_content.stdWrap.innerWrap.cObject
image = TEXT
image.value = <div class="screen">|</div>
}
}
}
If the above code dose not work then just write a comment and then I will take a look into it.

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.

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.

TYPO3 loading object based on current front end language

I'm running a Typo3 v9.5.4 Onepager style Website. The content is loaded directly from the tt_content. The Website has two FE languages (German/English).
I have a CTA button which has an anchorlink. The button is create with typoscript. I created one button for the German version and one for the English verson bc they have another value and another ancorlink.
I'm not sure if I can access a tt_content field directly from a fluid viewhelper. This is my code i've tried
<f:if condition="{tt_content.sys_language_uid} == 1">
<f:then>
<f:format.raw>{buttonEn}</f:format.raw>
</f:then>
<f:else>
<f:format.raw>{buttonDe}</f:format.raw>
</f:else>
</f:if>
This is my Typoscript for the two button Objects
lib.buttonDe = TEXT
lib.buttonDe {
value = German Text
stdWrap.typolink.parameter = #anchorlinkDE
stdWrap.typolink.ATagParams = class="button"
}
lib.buttonEn = TEXT
lib.buttonEn {
value = English Text
stdWrap.typolink.parameter = #anchorlinkEN
stdWrap.typolink.ATagParams = class="button"
}
And this is the typoscript that loads the Content, the Languages Menu and the Fluidtemplate (the Onepager Content is loaded without a Fluidtemplate, it loads the content directly from tt_content):
//--------------------- One Pager Content
lib.sectionContent = HMENU
lib.sectionContent {
excludeUidList = 12,13,16,17,29
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
orderBy = colPos,sorting
# Only selects Content where CE Layout is 0
where = (tt_content.layout = "0")
}
wrap = <div class="container">|</div>
renderObj < tt_content
}
30 = TEXT
30 {
wrap = </section>
}
}
}
}
}
}
//---------------------
// Language Selector
lib.langmenu = HMENU
lib.langmenu {
special = language
addQueryString = 1
special.value = {$config.language.uids}
1 = TMENU
1 {
wrap = <ul class="dg-langmenu row">|</ul>
NO = 1
NO {
stdWrap.current = 1
stdWrap.setCurrent = {$config.language.labels}
allWrap = <li class="col s6">|</li>
}
ACT < .NO
ACT.doNotLinkIt = 1
ACT.allWrap = <li class="act col s6">|</li>
}
}
page = PAGE
page{
10 = FLUIDTEMPLATE
10 {
templateName = TEXT
templateName.stdWrap{
cObject = TEXT
cObject{
data = levelfield:-2,backend_layout_next_level,slide
override.field = backend_layout
split {
token = pagets__
1.current = 1
1.wrap = |
}
}
ifEmpty = onePager
}
templateRootPaths {
10 = {$path.privat}Templates/
}
layoutRootPaths {
10 = {$path.privat}Layouts/
}
partialRootPaths {
10 = {$path.privat}Partials/
}
variables{
buttonDe < lib.buttonDe
buttonEnd< lib.buttonEn
}
}
So I'd like to load the buttonEn if the content has the sys_language_uid 1 (English) else I want it to load the buttonDe.
Do I need to create an Typoscript Object and then load this Object into the f:if viewhelper? If so how do I create this Typoscript Object.
Thanks for your help!
The easy way (pure typoscript)
lib.button = TEXT
lib.button {
value = English text
lang.de = Deutscher Text
stdWrap.typolink.parameter = #anchorlinkDE
stdWrap.typolink.ATagParams = class="button"
}
[siteLanguage("locale") == "en_EN.UTF-8"]
lib.buton.stdWrap.typolink.parameter = #anchorlinkEN
[global]
but the professional solution is configuring your labels in a language file (see answer from Thomas Löffler) and use:
lib.button = TEXT
lib.button {
lib.button.data = LLL:EXT:site_extension/Resources/Private/Language/locallang.xlf:button_label
stdWrap.typolink.parameter = #anchorlinkEN
stdWrap.typolink.ATagParams = class="button"
}
[siteLanguage("locale") == "de_DE.UTF-8"]
lib.buton.stdWrap.typolink.parameter = #anchorlinkDE
[global]
For language dependent constant data you might use typoscript conditions to redefine a value for your non default languages. (or define a fallback and conditions for each language.)
You should use a locallang file and refer to it in TypoScript.
Create a locallang file (copy an existing and remove all values) named locallang.xlf
Add your english label in there
Create a locallang file in the same folder with prepending de. in the filename (de.locallang.xlf) and add the german label
Refer to it in the TypoScript by using lib.button.data = LLL:EXT:your_ext/path/to/locallang/locallang.xlf:buttonLabel, see https://docs.typo3.org/typo3cms/TyposcriptReference/DataTypes/Index.html#lll
This TS getText function gets the label depending on the set language ID automatically and you only need one TS for the button.
Example: https://docs.typo3.org/typo3cms/TyposcriptIn45MinutesTutorial/UsingGetText/Index.html

Typo3 Adding a class to the body tag on a specifc page

I'm trying to figure out how conditionally add a class to the body tag of a specific page. I'm trying to do it via typoscipt but haven't been able to figure it out. Maybe there's a better way to do it though. The site is using Typo3 version 4.4.6
I've tried this which didn't work
page.4.bodyTag >
page.4.bodyTagCObject = TEXT
page.4.bodyTagCObject {
field = uid
wrap = <body class="uid-|">
}
Any help or pointers would be greatly appreciated!
Figured it out!
[globalVar = TSFE:id = 4]
page.bodyTag = <body class="page-speakers">
[end]
We use the follwing snippet for TYPO3 4.5 and TYPO3 6.2. Outputs class and id like this on every page. Just style your css.
<body id="pid13" class="be- rpid13 level1 no-subs">
Snippet to place into root setup:
page {
bodyTagCObject >
bodyTagCObject = COA
bodyTagCObject {
### id of page in root level:
10 = TEXT
10.data = levelfield:1, uid
10.dataWrap = id="pid{TSFE:id}" class="be-{TSFE:beUserLogin} rpid|
### current level/depth of page
20 = TEXT
20.data = level:1
20.noTrimWrap = | level| |
### if page has subpages
30 = TEXT
30.value = has-subs
30.if.isTrue.numRows {
table = pages
where = pid=this
}
### if page has NO subpages
40 = TEXT
40.value = no-subs
40.if.negate = 1
40.if.isTrue.numRows {
table = pages
where = pid=this
}
50 = TEXT
50.value = "
stdWrap.noTrimWrap = |<body |>|
}
}
Since TYPO3 Version 9:
# Body Classes
[page["uid"] == 1]
page.bodyTag = <body class="home">
[END]
Following will do
page.bodyTag >
page.bodyTagCObject = TEXT
page.bodyTagCObject.value= skin-blue
page.bodyTagCObject.wrap = <body class="|">

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" />
}
}