Typolink content in menu? - typo3

I am trying to make a menu that displays the page's first content element header and image and have them be links. But the typolink part doesn't seem to work for me:
lib.menu = HMENU
lib.menu {
1 = TMENU
1.NO {
doNotLinkIt = 1
wrapItemAndSub = <div>|</div>
stdWrap.cObject = CONTENT
stdWrap.cObject {
table = tt_content
select {
pidInList.field = uid
}
renderObj = COA
renderObj {
10 = TEXT
10.field = header
10.typolink.parameter.field = uid
}
}
}
}

Just to add give the full working example. Using section.field = uid you can link to the content element itself.
lib.menu = HMENU
lib.menu {
1 = TMENU
1.NO {
doNotLinkIt = 1
wrapItemAndSub = <div>|</div>
stdWrap.cObject = CONTENT
stdWrap.cObject {
table = tt_content
select {
pidInList.field = uid
}
renderObj = COA
renderObj {
10 = TEXT
10.field = header
10.typolink {
parameter.field = pid
section.field = uid
}
}
}
}
}

Related

get altText in renderObject in typoscript

i have the following typoscript which works as expected:
table = tx_news_domain_model_news
select {
selectFields = tx_news_domain_model_news.*, rand()
pidInList = 111
max = 1
orderBy = rand()
languageField = sys_language_uid
}
renderObj = COA
renderObj {
10 = FILES
10 {
references {
table = tx_news_domain_model_news
uid.data = uid
fieldName = fal_media
}
renderObj = IMAGE
renderObj {
wrap = <div class="news-list-item__image">|</div>
file.import.data = file:current:originalUid
file.width = 600c
file.height = 345c
}
}
....
but i need an alt attribute for the image too and don`t know how to achieve this:
renderObj {
wrap = <div class="news-list-item__image">|</div>
file.import.data = file:current:originalUid
file.width = 600c
file.height = 345c
altText = ?????
}
Is there a possibility to get the alt attribute here?
Thanks!
This should work:
renderObj {
// your code
titleText.data = file:current:title
altText.data = file:current:alternative
}

How to get first image in tt_content for meta og:image

I'm trying to fetch the first existing image in tt_content to be used in Open Graph (og:image) if any images in tt_content.
page.headerData {
1 = COA
1 {
10 = FILES
10 {
references {
table = tt_content
uid.field = uid
fieldName = image
}
renderObj = TEXT
renderObj {
typolink {
parameter.data = file:current:publicUrl
forceAbsoluteUrl = 1
returnLast = url
}
wrap = |,
}
stdWrap {
listNum = 0
# Use logo image if none is available
ifEmpty.cObject = TEXT
ifEmpty.cObject.typolink {
parameter = typo3conf/ext/my_ext/Resources/Public/Images/logo.png
forceAbsoluteUrl = 1
returnLast = url
}
wrap = <meta property="og:image" content="|">
}
}
}
}
The code above only returns the fallback (logo). Great for pages and tt_content without images, but I would expect different from pages with image(s) in tt_content.
I report here the nice snippet found on https://docs.typo3.org/m/typo3/docs-snippets/master/en-us/2014/Index.html#add-facebook-open-graph-og-image-metatags-for-content-elements-with-typo3-6-0-and-fal
I simplified it a bit; hope it is not too much simplified but it should work:
page.headerData.200 = CONTENT
page.headerData.200 {
table = tt_content
select {
where = {#colPos}=0
selectFields = uid
}
renderObj = FILES
renderObj {
references {
table = tt_content
uid.field = uid
fieldName = image
}
maxItems = 1
renderObj = TEXT
renderObj {
data = file:current:publicUrl
stdWrap {
wrap = <meta name="og:image" content="|" >
}
}
}
}
Here is #riccardo-de-contardi's snippet with a fallback
page.headerData.1569221029 = CONTENT
page.headerData.1569221029 {
table = tt_content
select {
where = {#colPos}=0
selectFields = uid
}
renderObj = FILES
renderObj {
references {
table = tt_content
uid.field = uid
fieldName = image
}
maxItems = 1
renderObj = TEXT
renderObj {
data = file:current:publicUrl
stdWrap {
wrap = |,
}
}
}
stdWrap {
listNum = 0
# Use logo image if none is available
ifEmpty.cObject = TEXT
ifEmpty.cObject.typolink {
parameter = typo3conf/ext/my_ext/Resources/Public/Images/logo.png
forceAbsoluteUrl = 1
returnLast = url
}
wrap = <meta property="og:image" content="|">
}
}

How to get media content in typoscript assigned to the current page?

I have 3 pics that are assigned to my page and I am trying to put them into a variable in typoscript.
Here is my code:
temp.pics = FILES
temp.pics {
references {
table = pages
uid.data = page:uid
fieldName = media
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:originalUid
altText.data = file:current:title
wrap = <li>|</li>
}
stdWrap.wrap = <ul id="Gallery" class="gallery">|</ul>
}
page.10 {
variables {
pics < temp.pics
}
}
And in my HTML layout I only get:
<ul id="Gallery" class="gallery"></ul>
Does anybody have an idea why it is empty?

Typo3 - TMENU get Content from Colpos

i have an TMENU, in that Menu I would have the Content from the Subpages in the Menu. On every Page is an Col (colpos=0) with Content. Is it possible to get the Content from there to the Menu?
lib.mainmenu = HMENU
lib.mainmenu {
1 = TMENU
1 {
wrap = <ul id="mainmenu">|</ul>
expAll = 1
NO {
wrapItemAndSub = <li>|</li>
ATagParams = class="drop"
}
}
2 = TMENU
2 {
wrap = <div class="dropdown_produkte"><div class="nav-tabs"><ul>|</ul></div></div>
NO {
wrapItemAndSub = <li>|</li>
}
2.40 = CONTENT
2.40 {
table = tt_content
select.pidInList.field = pid
select.where = colPos=0
select.languageField=sys_language_uid
wrap = <div class="teaser">|</div>
}
}
}
There is already such a menu defined in css_styled_content
typo3/sysext/css_styled_content/static/setup.txt
# "Menu of subpages to these pages + sections - liststyle"
7 < .1
7 {
stdWrap {
outerWrap = <ul class="csc-menu csc-menu-7">|</ul>
}
1.expAll = 1
2 < .1
2 {
sectionIndex = 1
sectionIndex.type = header
wrap = <ul>|</ul>
NO.wrapItemAndSub = <li class="csc-section">|</li>
}
}
If you are going to use typoscript in your project (wich you hardly need anymore when you develope with fluid + vhs) than css_styled_content is always a good reference point
Here is my Solution
lib.mainmenu = HMENU
lib.mainmenu {
1 = TMENU
1 {
wrap = <ul id="mainmenu">|</ul>
expAll = 1
NO {
wrapItemAndSub = <li>|</div></li>
ATagParams = class="drop"
}
submenuObjSuffixes = a || b || c || d || e
}
2a < .1
2a {
wrap = <div class="dropdown_produkte">|</div>
stdWrap.cObject = COA
stdWrap.cObject {
20 = HMENU
20 {
special = directory
special.value.data = field:pid
1 = TMENU
1 {
expAll = 1
wrap = <div class="nav-tabs"><ul>|</ul>
NO {
wrapItemAndSub = <li>|</li>
#stdWrap.dataWrap = <h2>|</h2>
#linkWrap = | |*| /
ATagParams = class=submenu
}
ACT < .NO
ACT = 1
ACT {
ATagParams = class=submenuActive
}
RO < .ACT
}
}
40 = CONTENT
40 {
table = pages
select {
pidInList.field = pid
orderBy = sorting
}
renderObj = COA_INT
renderObj {
10 = TEXT
#10.field = title
10.wrap = |
20 = LOAD_REGISTER
20 {
meinRegister.cObject = TEXT
meinRegister.cObject.field = uid
}
50 = COA
50 {
###########
20 = CONTENT
20 {
table = tt_content
select {
pidInList.data = register:meinRegister
where = colPos=0
}
}
###########
}
}
}
}
}
}
As I faced a similar issue today, I wanted this question to be up to date. (Using TYPO3 8.7.4 with fluid_styled_content.)
lib.mainmenu = HMENU
lib.mainmenu {
1 = TMENU
1 {
wrap = <ul id="mainmenu" class="level1">|</ul>
expAll = 1
NO {
wrapItemAndSub = <li>|</li>
ATagParams = class="drop"
}
}
2 < .1
2 {
wrap = <div class="wrapper">|</div>
stdWrap.innerWrap = <ul class="level2">|</ul>
stdWrap.append = CONTENT
stdWrap.append {
table = tt_content
select {
pidInList.field = pid
where = colPos = 5 and deleted = 0 and hidden = 0
}
stdWrap.wrap = <div class="content">|</div>
}
}
3 < .2
3 {
NO.wrapItemAndSub = <li>|</li>
wrap = <ul class="level3">|</ul>
stdWrap.append >
}
}
That way (of course I simplified it here) I was able to add custom populated content from a specific column (defined in a backend_layout) to be rendered inside a navigation panel.

alt/title attributes in img-tag in typo3

I use the following Typoscript to get a menu of pages with images from respective page resource.
How can i get the page-title (or page-description etc.) to the images alt and/or title-tags?
tt_content.menu.20.4 >
tt_content.menu.20.4 = COA
tt_content.menu.20.4 {
wrap = <div>|</div>
10 = HMENU
10 {
special = directory
special.value.field = pages
1 = TMENU
1 {
noBlur = 1
NO = 1
NO {
stdWrap >
stdWrap {
cObject = COA
cObject {
10 = FILES
10 {
references {
table = pages
uid.data = field = uid
fieldName = media
data = levelmedia:-1, slide
treatIdAsReference = 1
listNum = 0
}
renderObj = IMG_RESOURCE
renderObj {
file.import.data = file:current:publicUrl
file.maxW = 100
file.maxH = 60
required = 1
}
stdWrap.wrap = <img src="|" title="???pagetitle???" alt="???pagetitle???">
}
}
}
wrapItemAndSub = <div>|</div>
}
}
}
}
Have you tried it with dataWrap?
i think it could be something like this
stdWrap.dataWrap = <img src="|" title="{field:title}" alt="{field:title}">
or maybe...
stdWrap.dataWrap = <img src="|" title="{page:title}" alt="{page:title}">
this works for me now
cObject = COA
cObject {
10 = FILES
10 {
references {
table = pages
uid.data = field = uid
fieldName = media
data = levelmedia:-1, slide
treatIdAsReference = 1
listNum = 0
}
renderObj = COA
renderObj {
10 = IMG_RESOURCE
10.stdWrap.wrap = <img src="|
10.file.import.data = file:current:publicUrl
20 = TEXT
20.stdWrap.wrap = " title="|
20.data = file:current:title
30 = TEXT
30.stdWrap.wrap = " alt="|" />
30.data = file:current:title
}
stdWrap.wrap = |
stdWrap.required = 1
}
}