typo3 add image resource as background - typo3

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 ?

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.

TYPO3 Render content from subpages via typoscript

i am new to typoscript. I tried to render content from some subpages on an archive page.
I am not sure why my code is displaying nothing.
Firstly I am trying to iterate through my subpages
within that code
stdWrap.wrap = <div class="row"> | </div>
table = pages
select {
orderBy = sorting
# If this element is inserted as sitemap, consider the startingpoint
pidInList.field = uid
#max = 1
begin = 0
}
Secondly i am itarating through my tt_content table and trying to get the value of the column header and render that on my archive page.
The Code is working until
<div class="row"> | </div>
Full Code here:
lib.content = COA
lib.content {
stdWrap.wrap = <div class="row"> | </div>
table = pages
select {
orderBy = sorting
# If this element is inserted as sitemap, consider the startingpoint
pidInList.field = uid
#max = 1
begin = 0
}
renderObj = COA
renderObj {
stdWrap.wrap = <div class="testfestinner"> | </div>
10 = CONTENT
10.wrap = <h3>|</h3>
10 {
table = tt_content
select {
pidInList.field = uid
where = colPos = 212
orderBy = sorting
}
renderObj = COA
renderObj.10 = TEXT
renderObj.10.field = header
}
}
}
I am not sure where and how to debug that code.
Thanks in advance.
Something like table = pages can not be assigned to a COA directly.
You need a cObject of the type CONTENT for that purpose. Just like the one you assigned to the renderObj.

TYPO3 Menu Double up

I have this custom menu setup based on the default section menu. When testing on one content element, it looks good... When I add a second content element to the page both get added to each menu item.
Anyone know what's going on here?
tt_content.menu.20.3.1.sectionIndex.useColPos = -1
tt_content.menu.20.101 < tt_content.menu.20.3
tt_content.menu.20.101 {
1.NO {
stdWrap.cObject = CONTENT
stdWrap.cObject {
table = tt_content
select {
pidInList.field = uid
}
renderObj = COA
renderObj {
10 = FILES
10 {
stdWrap.wrap = <div class="menu-img">|</div>
references {
table = tt_content
fieldName = image
}
renderObj = IMAGE
renderObj {
file {
import.data = file:current:uid
treatIdAsReference = 1
width = 100c
height = 100c
}
altText.data = file:current:alternative
titleText.data = file:current:title
stdWrap.typolink.parameter.data = file:current:link
}
maxItems = 1
}
20 = TEXT
20.field = header
30 = TEXT
30.field = rowDescription
}
}
}
}
This is currently outputting:
<ul>
<li><img/>Heading1Desc1<img2/>Heading2Desc2</li>
<li><img/>Heading1Desc1<img2/>Heading2Desc2</li>
<ul>
What it should be:
<ul>
<li><img/>Heading1Desc1</li>
<li><img2/>Heading2Desc2</li>
</ul>
It is about your CONTENT object.
your selection is strange:
select {
pidInList.field = uid
}
you select all tt_content elements which are in the page with the uid of the current content element.
And your rendering is executed for each record found.
Do you really need to select the contentelement with a cObject again? I think in the menu it should be the current context.
add on:
I would try something like this to render the image before the text (which should be available by default):
before just for the image instead of stdWrap with a full query of all CEs and with a COA for all fields.
have a look to the correct fieldname!
1.NO {
before.cObject = FILES
before.cObject {
stdWrap.wrap = <div class="pic">|</div>
references {
table = tt_content
uid.data = uid
// 'image' or 'media' or ... ???
fieldName = image
}
renderObj = IMAGE
renderObj {
stdWrap.wrap = <div class="pic">|</div>
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"
// don't do a link inside a link =:-O
#stdWrap.typolink.parameter.data = file:current:link
}
maxItems = 1
}
}
I have tried this many different ways and cannot get it working with the image and fields. So instead I have simply patched my original code using by adding: tt_content.menu.20.101.maxItems = 1 and adding a wrap to the renderObj.
I know this is not how it should be done, but it works for now. But if anyone knows the correct way of doing it let me know!

TYPO3 TypoScript: Display a list of subpages with content on parent page

I am trying to create an archive page that displays a list of subpages, similar to WordPress but display the parent's subpages instead of posts. I want the archive page to include the following from the subpage:
Title
First image
First 150 words of regular text element
At the moment I can display a page title, but that's where I got stuck. I am placing the code in a sub template. Here is the code.
lib.portfoliolist = CONTENT
lib.portfoliolist.table = pages
lib.portfoliolist.select {
pidInList = this
}
lib.portfoliolist.renderObj = COA
lib.portfoliolist.renderObj {
stdWrap.wrap = <div class="project">|</div><hr />
10 = TEXT
10 {
field = title
wrap = <h2>|</h2>
10.typolink.parameter.field = uid
}
}
If it helps, all of the images are within the fileadmin/user_upload/ directory, and this is my page structure:
Root
Home
About
Project Portfolio
Project 1
Project 2
Blog
Contact Us
Seems like I figured it out myself, all I had to do was call for content in a separate query. For those that are looking to achieve something similar, here is the code I used to help you out.
lib.portfoliolist = CONTENT
lib.portfoliolist.table = pages
lib.portfoliolist.select {
orderBy = sorting ASC
}
lib.portfoliolist.renderObj = COA
lib.portfoliolist.renderObj {
stdWrap.allWrap = <div class="row">|</div>
stdWrap.wrap = <div class="project col-lg-6 col-md-6 col-sm-12 col-xs-12">|</div>
10 = TEXT
10 {
field = title
wrap = <h2>|</h2>
typolink.parameter.field = pages.uid
}
20 = CONTENT
20 {
table = tt_content
select {
pidInList.field = uid
selectFields = header, bodytext
orderBy = sorting ASC
}
renderObj = COA
renderObj {
30 = TEXT
30.value {
field = bodytext
wrap = <div>|</div>
}
}
}
}

Typo3 resources media files/sys_file_reference for TMENU

How can I use resources media files -> Description (Caption) for altTag/altText in menu.
In TYPO3 you have the possibility to use the page properties for a resource image and to set additional metadata. I found this reference: data [sys_file_reference] [6] [description]
NO = 1
NO {
ATagTitle.field = title
wrapItemAndSub = |</li>
allWrap = <li>|
after.cObject = IMAGE
after.cObject {
file.import.field = media
file.import = uploads/media/
file.import.listNum = 0
file.width = 250c
altText = {???:description}
altText.insertData = 1
}
stdWrap.htmlSpecialChars = 1
}
Since TYPO3 6.0 the media field uses File Abstraction Layer (FAL) to create references to uploaded objects (e.g. images). Because of this change, you can't use the IMAGE content object to fetch the inserted object, but first have to use the FILES content object.
For you case, the TypoScript should look like this:
after.cObject = FILES
after.cObject {
references.data = levelmedia:-1, slide
references.listNum = 0
renderObj = IMAGE
renderObj.altText.data = file:current:description
renderObj.file {
import.data = file:current:publicUrl
width = 250c
}
}
References: http://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Files/Index.html