Typoscript: render HTML table with database values - html

Im completely new to typoscript therefore I have quite a hard time with the syntax but I think I am getting there.
My task is to render an HTML table and fill it with values from a database table (doesn't matter which one). In my case I took the tt_content table and tried to fill my HTML table with the "header" field and the "bodytext" field.
So I made a completely empty template and wrote the following code in the "setup" field of the template. I added some headers and texts to the sites I have to test my code but I get a completely empty page not even the "table" HTML tags are there.
After 4 days of research I still don't know what my problem is here so I am quite desperate.
Here is what I have so far:
page = PAGE
page.typeNum = 0
lib.object = COA_INT
lib.object {
10 = TEXT
10.value = <table>
20 = CONTENT
20.wrap = <tr>|</tr>
20 {
table = tt_content
select {
orderBy = sorting
}
renderObj = COA
renderObj {
10 = COA
10 {
10 = TEXT
10 {
field = header
wrap = <td>|</td>
}
20 = TEXT
20 {
field = bodytext
wrap = <td>|</td>
}
}
}
}
20 = TEXT
20.value = </table>
}
If someone could help me out here it would be much appreciated.
Thanks in advance.

Check if you have any 'template parser' running.
go to template -> choose 'Info/modify' and click on 'edit the whole ...'
There choose the includes tab and include css_styled_content' (Yes, there is another way of parsing your content, with fluid_styled_content'. you can choose that instead if you are on TYPO3 7.6.* or higher)
These 'parsers' will give you all the needed typoscript included to parse and render your content. Without these, nothing will be rendered when you want to render content from the backend.
second: your typoscript is wrong
You have made a content array (lib.content is a Content Object Array) and filled it with content. But you overwrite the content with key 20.
change
20 = TEXT
20.value = </table>
to
30 = TEXT
30.value = </table>
third: you have created a Page object but you did not add your COA into that page object.
Try this:
page = PAGE
page.10 < lib.object
What this does is include your lib.content in the Page Object at 'level' 10
you can also do
page.20 = TEXT
page.20.value = hello world
This will be rendered after your lib.content.
As you could notice. It is a bit as writing a big Array (because typoscript is a big Array ;)
Beware that you place your lib.content ABOVE the page object declaration. else it will not be able to include it.
There is also a slack channel for TYPO3 you can join if you have other questions. People over there are more then willing to help you.
https://forger.typo3.org/slack

Related

Rendering content element by Uid

I'm trying to render a content element only by having it's Uid.
It's supposed to be the login form of fe_login placed directly into a navigation Overlay.
I tried saving the element into a variable by using CONTENT. It did not work, obviously.
But I'm not even sure if I used used the correct syntax.
page.10.variables.contentLogin = CONTENT
page.10.variables.contentLogin {
table = tt_content
select.where {
uidInList = 32
pidInList = 0
}
}
And the same for lib.loginContent.
Added both respectively with
{contentLogin -> f:format.raw()}
<f:cObject typoscriptObjectPath="lib.loginContent"/>
But this only renders the object I already have on this page and not the element I am looking for globally.
EDIT: I found the solution. See my own answer.
I found the solution. The problem in my code is the select.where statement.
The working code is:
lib.loginContent = CONTENT
lib.loginContent {
table = tt_content
select {
uidInList.field = myUid
pidInList = 0
}
}
and in HTML
<f:cObject typoscriptObjectPath="lib.loginContent" data="{myUid: 32}"/>
The change I made was to just delete the ".where" from the select.
After checking the Doc again and again I finally realized my mistake. I hope other people will find this question and answer useful as I did not find anything on the internet that could help me with the problem.
Code for static content element:
lib.foo = CONTENT
lib.foo {
#tt_content is the default table. I just like to write down where Im looking for it
table = tt_content
select {
uidInList.field = Your ContentElement ID goes here!
pidInList = 0
}
}
<f:cObject typoscriptObjectPath="lib.loginContent">
That's it. Enjoy!
The f:cObject-viewhelper has a data-attribute for passing any data to the called TypoScript-object. The passed data is accessible as fields in TypoScript:
The Fluid part:
<f:cObject typoscriptObjectPath="lib.loginContent" data="{myUid: 123}"/>
And in TypoScript:
lib.loginContent = CONTENT
lib.loginContent {
table = tt_content
select.where {
uidInList.field = myUid
pidInList = 0
}
}

Trying to get the routeName but it's always empty

I tried to get the routeName from the URL because i need to set another class in the Layout of the body if i'm on the /Category page.
#{string classContent = Request.QueryString["routeName"] != "/Category" ? "container" : "";};
<div id="Content" class="body-wrapper #classContent">
My problem is, Request.QueryString["routeName"] is always empty and couldn't find why.
Does someone know why it's always empty or has a better approach for setting a different class if you're on a certain page?
In the end i solved it with that code:
var segments = Request.Url.AbsolutePath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
string classContent = "container";
if (segments.Count() > 1) { classContent = segments[1] != "category" ? "" : "container";}
Request.Url.AbsolutePath gets the whole URL.
After that i split the whole URL and save it into a list.
Then i test if the list is long enough to be on another site except home.
In the end i look if the second part of the url is /Category and save the Css class appropriate to the output of the url.

typo3: Change style of h2 header

I'm still fiddling with typo3 (Version: 6.2.15) and I have gotten none of the code I found on the net to work. What I want to do, is define that a header is always converted into:
<h2 class="title-divider">
<span> {HEADERTEXT} <span class="de-em"></span></span>
<small>{SUBHEADER}</small>
</h2>
What I tried:
Based on this website: https://axelerant.com/change-typo3-header-layout-options/
I was able to add new Header types, but when I use the code for the styling from this website, my header just disappears...
I also tried to use the code that was published at http://www.typo3-addict.com/2010/03/a-custom-header-layout/ but first, it doesn't work for me, and second I don't really get how I could change it to display the subheader.
Can anyone point me in the right direction, or even better give me a code example that explains the concept that is followed, since it seems to be a misunderstanding of the concept.
Thanks in advance!
Alright, a couple of ours into the documentation and I have found a solution that works:
I added
stdheader.10.2 = COA
stdheader.10.2 {
setCurrent {
field = header
htmlSpecialChars = 1
}
key {
field = header_layout
ifEmpty = {$content.defaultHeaderType}
ifEmpty.override.data = register: defaultHeaderType
}
10 = TEXT
10.current = 1
20 = TEXT
20 {
field = subheader
stdWrap.noTrimWrap = | <span class="de-em"></span></span><small>|</small>|
stdWrap.required = 1
field.value =
}
stdWrap.dataWrap = <h2 class="title-divider">|</h2>
typolink.parameter.field = header_link
stdWrap.required = 1
}
stdheader.20.2 = COA
stdheader.20.2 {
wrap = <span style="display: none" class="hiddensubheader">|</span>
}
to the lib element in setup.ts.

TYPO3 templates and changes the div id

I have a Template in TYPO3 that i want to use to some pages, in here i have a DIV.
Is it possible depending on the page UID, to changes the DIV ID. its the only div thats changes content/image, and im looking to put this DIV inside my main.html template.
so if
UID = 2 <div id="topbanner_about"></div>
UID = 3 <div id="topbanner_drills"></div>
and so on....
Can i do this, and can i do it in TS (Typo Script) or how can i do this, so i dont need to make 5 templates.
You can do this by inserting a marker in your template. It would look somehow like this:
In the template:
[...]
<div id="topbanner_###ID_SUFFIX###"></div>
[...]
In the TypoScript, where the template is inserted:
10 = TEMPLATE
10 {
template = FILE
template.file = fileadmin/main.html
marks {
ID_SUFFIX = TEXT
ID_SUFFIX {
insertData = 1
# This makes sure that the output is valid and prevents XSS attacks
htmlSpecialChars = 1
value = {page:uid} # Use this to insert the page ID or
value = {page:subtitle} # Use to insert subtitle of page
... # Same works for other fields of the page record.
}
}
}
If the fields provided by default pages are not enough, you could add another field to the page records. The best way to do that would be to build an extension that does it.
I found a better solution, if i use ressource and add an image and on the next page do the same just with another images, then in my main TS i add this code.
lib.imageElement = FILES
lib.imageElement {
references {
data = levelmedia:-1,slide
listNum = 0
}
renderObj = COA
renderObj {
10 = IMAGE
10 {
file.import.data = file:current:originalUid
altText.data = file:current:title
}
}
}
It do the trick, then it shows a diffrent image in the top/header on every page.
But thx...

split data(Text) of a text field into two strings, and use each string on different section of a visualforce page

I have an account with a Note in notesandattachment related list.
I want to display the text of 8 lines, out of 50 lines on a section of visualforce page.
And remaining 42 lines in another section of same visualforce page.
what i know :
I need to split the notes.body into two substrings. One, with 8 lines of text and second one with 42 line.I need to use div tags to get this done on the visualforce page. I might be wrong.
Please suggest me, how do i achieve this.
Appreciate the help.
You can split the text in controller by using split() method like this
String allLines[] = allText.split('\n');
String first8Lines = '';
String restLines ='';
for(Integer i =0; i<8 ; i++){
first8Lines += allLines[i];
}
for(Integer i =7; i<50 ; i++){
restLines += allLines[i];
}
And then put {!first8Lines} in one place and {!restLines} in another