How to access data from FLUIDTEMPLATE file and render that content in our desired file? - typo3

I have my package from sitepackagebuilder (v9.5.14). I no good at Typoscript. I am using the optional menu navigation file MainBefore.html (my desired file) from bootstrap_package which I put in my stpkg extension because this file is globally available in the FE alongside main menu. I try to explain my doubt in the two following examples.
First one is clear to me. usually I do things like this, (My only known typoscript way to access and render things).
Example 1:
In typoscript
lib.stdContent = FLUIDTEMPLATE
lib.stdContent {
file = EXT:sitepackagebuilder/Resources/Private/Partials/Page/DropIn/Navigation/Data.html
variables {
mylabel = TEXT
mylabel.value = Label coming from TypoScript!
}
}
In Data.html
<h4>Hello TYPO3</h4>
<h3 hidden>{mylabel}</h3>
MainBefore.html
....
<div class="from-data-file"><f:cObject typoscriptObjectPath="lib.stdContent" /></div>
....
The above example will work.
Example 2:
But this following example is my doubt.
page.10 = FLUIDTEMPLATE
page.10.variables.userInfoForChat = COA_INT
page.10.variables.userInfoForChat {
10 = FLUIDTEMPLATE
10 {
file = EXT:company/Resources/Private/Partials/Page/DropIn/Navigation/Data.html
variables {
mylabel = TEXT
mylabel.value = Label coming from TypoScript!
}
}
}
How can I access variables in Data.html and render content in MainBefore.html like example 1? Correct me If I am wrong
Both files are in same location.

First: you are doing very complicated things. normaly stacking templates inside each other is not necessary. so the main question would be: What do you intend to do?
Then we can find a simple way to do it.
I try to identify your intention:
you have a main template (main = main for this example, otherwise it is just a small part of the general page rendering) where you want to have a variable, which is filled from another template, where some variable is inserted.
Some information is missing as these would not be necessary when all values are static like in your example.
There must be something non static as you use a uncached COA_INT and the name userInfoForChat hints to something user specific, which of course is not cachable.
My question is: why do you put a complete fluid templating in the variable, when it should be enough to have only some uncached values in it and stay with just one set of fluid template. (That set already could consists of template, layout and a lot of partials)

Related

Condition for backend layout name in Typo3 10+

I'm looking for a way to render a partial for when an element is placed it on a part of the backend layout and another partial for when the same element is placed it on another part of the backend layout.
My backend layout names are "Header" on top and "Normal" on the bottom. I want to render text-media element with one partial for when is on Header and another partial for when is on Normal.
For what I could find online seems that this must be done with typoscript. Particualrly I want to use typoscript condition because is the one that make more sense on my head.
I'm aware of this but the answers are not helping me at all.
This is the one that looks like something I could use.
[page["backend_layout"] == 'pagets__2']
page.bodyTagCObject.value.wrap = <body id="uid|" class="fullpage">
[end]
Any help is welcome even tutorials because clearly I have much to learn about typoscripting
You can pass the needed value as a variable to your FLUIDTEMPLATE-object.
The current backend-layout is available as pagelayout (Already with the 'backend_layout_next_level' taken into account).
page.10 = FLUIDTEMPLATE
page.10 {
variables {
pagelayout = TEXT
pagelayout.data = pagelayout
}
}
Solved it.
I have been able to solve this problem without useing Typoscript. (so I will keep ignoring typoscript :D )
Dropping the variables of the loaded templates (not partials) made me realized that there was a property holding the colPos of the backend layout so all I had to do was an if condition on the textmedia default template.
<f:if condition="{data.colPos} == 1">
If the colPos of the backend layout is 1 print something
</f:if>

Add a static template to my typo3 extension

I have created an extension with sitepackagebuilder.com and the idea is just to write some static html.
I know that when you have a controller you can call the templates by following the convention names. But what if you don't have a controller? What I need, at least for now, is just to install the extension, add the plugin into a page and get some static content in that page.
I can imagine that this is set in a typoscript file but I'm quite noob with all the typoscript thing.
I'm getting this error:
'No Content Object definition found at TypoScript object path "tt_content.list.20.heboorganigram_organigram"'
Until I define that object in my typoscript file. I have tried this.
tt_content.list.20.heboorganigram_organigram = PAGE
tt_content.list.20.heboorganigram_organigram.10 = TEMPLATE //(or FLUIDTEMPLATE same result)
tt_content.list.20.heboorganigram_organigram.10.template = FILE
tt_content.list.20.heboorganigram_organigram.10.template.file = fileadmin/Organigram.html
And then I don't get an error but I also don't get the content from my Organigram.html, this is just trying stuffs, I actually don't know if this is what I need to do.
Before creating new Content Elements you first have to create the Page Template, for that have a look at the sitepackage tutorial https://docs.typo3.org/m/typo3/tutorial-sitepackage/master/en-us/FluidTemplates/Index.html
If you already got the page template, have a look at https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/ContentElements/AddingYourOwnContentElements.html
Provided you already did the steps above, for getting the frontend output you are interested in the step Configure the frontend rendering
So the TypoScript should look something like this:
lib.contentElement {
templateRootPaths.200 = EXT:heboorganigram/Resources/Private/Templates/
}
tt_content {
examples_newcontentelement =< lib.contentElement
examples_newcontentelement {
templateName = NewContentElement
}
}
Then you need to place your Organigram.html file in the Templates Folder in inside the sitepackage.

How to use a typo3 constant in an href?

To make things easier, I can define the main url of my page as a constant in a template: tx_dti.settings.url = https:/someserver/
Now I like to use this constant in my text element to link an internal page eg:
Contact Form
Unfortunately my above mentioned approach does not work.
What is the correct syntax to replace the server with a constant?
The goal is that I only want to change the constant when I move from a dev to a productive server.
in general:
You can not use typoscript constants outside typoscript templates (constants and setup). If you want to use the value of a typoscript constant in other context you need to transfer the value.
If you want to use the constant in fluid you need to transfer the value to a fluid variable.
temp.content = FLUIDTEMPLATE
temp.content {
template = ...
variables {
domain = TEXT
domain.value = {$myTSconstant}
:
}
}
or
settings {
domain = TEXT
domain.value = {$myTSconstant}
:
}
If you want to use the constant in a data field of a content element you might use a marker and replace the marker with typoscript as last step of rendering.
"<p>This is my text and here I use a marker: __MYMARKER__</p>"
the corresponding typoscript:
page {
:
stdWrap.replacement {
1.search = __MYMARKER__
1.replace = {$myTSconstant}
}
}
Note:
always use TS constants with a $ before the name inside the curly braces.
Don't confuse it with variable usage in fluid (without $).
regarding your problem:
as Riccardo mentioned: don't use constants for your links, even: don't build your links by hand. If you really need your domain in urls, automate it with a setting of config.absRefPrefix (preferrable to config.baseURL)
I guess that you could use config.absRefPrefix or config.baseURL (see https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/)
you can set in TypoScript constants:
tx_dti.settings.url = http://myserver
then in TypoScript Setup:
config.baseURL = {$tx_dti.settings.url}
or
config.absRefPrefix = {$tx_dti.settings.url}
Is this sufficient or am I misunderstanding your request?

Custom tags in TYPO3 content

new here, and also new to TYPO3.
I need to put something like [imagebox, title='box1'] into content editor and that will be replaced by a text and image with some javascript effect (text and image are managed in the DB elsewhere, the tag is just for the placement in the page).
I've read that TYPO3 has a mechanism for adding custom tags and I managed to make them accepted in the RTE.
I tried instead of [imagebox..... to use
<imagebox>box1</imagebox>
with something like this (copied from web):
tt_content.text.20.parseFunc.tags {
imagebox < lib.parseFunc.tags.link
imagebox = TEXT
imagebox.value= replaced
# imagebox = PHP_SCRIPT
# imagebox {
# stripNL = 0
# Pass a parameter from Typoscript to a PHP script:
# UID of the page containing the SINGLE view of tt_news
# id_singleView = 18
# Call the PHP script
# file = fileadmin/scripts/imagebox_parser.php
# }
}
lib.parseFunc.tags.imagebox < tt_content.text.20.parseFunc.tags.imagebox
should be able to replace content between tags.
I've commented call to php function just tried to get a text replacement for starters.
I've put that in the main root template Setup, but nothing is replaced.
I've also tried other examples from the web with no success.
Did anyone have situation like this?
Are there better approaches for that in TYPO3? (I'm using v7.6.23)
Any suggestion or hint is appreciated.
EDIT: using FSC on textmedia element
I think your examples are outdated. (the object PHP_SCRIPT is obsolete for a long time)
You might have a look at the documentation for your TYPO3 version:
https://docs.typo3.org/typo3cms/TyposcriptReference/7.6/Functions/Parsefunc/
you also need to enhance the parsefunc where you need it. That can depend on:
CSC or FSC?
which kind of content element (CE) do you use? (be sure to enhance the rendering of that CE)

How can I insert the current page title automatically into a TYPO3 template?

actually the title is the whole question.
I just want to modify the template so that the current page title is automatically shown (i'm working with html templates so I just need the bit of typoscript to get the page title out of the database)
I hope that's possible
It is. It's pretty simple to do. I'll assume you're using TemplaVoilà, because if you're not, you should be :-D
Start off by putting some HTML in your template with a dummy page title. Give it an ID attribute so it's easy to map. Like:
<h1 id="page-title">Page Title Here</h1>
Next, go into TemplaVoilà and map that <h1> element to the content type "TypoScript Object Path". When it prompts you for the object path, you can put in anything you want -- convention is that dynamic content is added in the "lib" namespace, so let's call it lib.pagetitle. When it asks you if you want to map this to "INNER" or "OUTER", choose "INNER" -- that will mean you're just mapping the space BETWEEN the <h1>...</h1> tags. ("OUTER" means you're replacing the whole element, including the tags, which we don't want here because we want this to stay an H1.) Save your template mapping.
Now go into your site's TypoScript template. Here you're going to insert the logic that fills in that space we just mapped with actual content. To insert the page title is a matter of a couple of lines of TypoScript:
lib.pagetitle = TEXT
lib.pagetitle.data = page : title
What this says is "take the space in the template that I mapped to lib.pagetitle. Create a content object in that space of type TEXT. Then fill that content object with the title of the page."
Save your TypoScript template. Now you're done!
This probably sounds complicated at first glance, and it is, but the nice thing about this system is that it's amazingly flexible. Inserting text dynamically is just the beginning. The TypoScript Reference (a.k.a. the "TSRef") has all the details -- look up "getText" to get a flavor, that's the function that makes the "page : title" call in your TypoScript template drop in the page title.
TSRef is your friend. I keep a printed copy of it at my desk -- if you want to make TYPO3 sing, it is your songbook.
I prefer the vhs solution:
{v:page.info(field:'title')}
https://fluidtypo3.org/viewhelpers/vhs/master/Page/InfoViewHelper.html
lib.pagetitle = RECORDS
lib.pagetitle {
source.data = page:uid
tables = pages
conf.pages = TEXT
conf.pages.field = nav_title
}
To get current page title:
lib.pagetitle = TEXT
lib.pagetitle.field=title
For meta data :
Its very important to place meta after header tag when we are gone through mobile compatible website
In order to prevent quirks mode in IE9 I need to add this lines at the very top of every HTML page:
You can write the whole header by yourself, by adding disableAllHeaderCode = 1 to your typoscript or you can hack it by adding your meta tag directly to the head tag:
page.headTag = <head><meta http-equiv="X-UA-Compatible" content="IE=edge" />
Place this at your typoscript
meta.X-UA-Compatible = IE=edge,chrome=1
httpEquivalent: (Since TYPO3 4.7) If set to 1, the http-equiv attribute is used in the meta tag instead of the “name” attribute. Default: 0.
For more information about TYPO3 stuff you may visit my blog
https://jainishsenjaliya.wordpress.com/2013/10/10/put-meta-tag-on-top-of-header-section-in-typo3/
If you want to use this in a fluid page template, you can also simple use:
{data.title}
to access the page title.
You can current page title by following typoscript:
lib.pagetitle = TEXT
lib.pagetitle.data = page : title
and then use this object to your page using typoscriptObjectPath like following way:
<f:cObject typoscriptObjectPath="lib.pagetitle"/>
If you want to use a fluid only solution, install the VHS extension and you can output the page title without using any TypoScript at all like this:
Tag Example:
<v:page.header.title title="NULL" whitespaceString="' '" setIndexedDocTitle="1">
<!-- tag content - may be ignored! -->
</v:page.header.title>
Inline Example:
{v:page.header.title(title: 'NULL', whitespaceString: '' '', setIndexedDocTitle: 1)}
lib.page_title = CONTENT
lib.page_title {
table = pages
select {
where = uid = 2
}
renderObj = COA
renderObj {
10 = TEXT
10 {
field = title
wrap = <h1 class="page_title">|</h1>
}
20 = TEXT
20 {
field = subtitle
stdWrap.required = 1
stdWrap.wrap = <h5>|</h5>
}
}
}
call the lib.page_title where want to render typoscript with this lines
<f:cObject typoscriptObjectPath='lib.page_title' />
I hope this helps !!!
The question is quite old but I still want to add something I never read here.
TYPO3 offers many things concerning the header, and it's right that it's also possible to render it completely individual. Nevertheless all the nice options of TYPO3 are more or less disabled by the individual solution.
So first the direct answer on the question:
The default page title can be overridden like this
config.pageTitle.stdWrap.override.cObject < lib.pagetitle
If several page types are defined and the title shall be set individually for each type, the configuration can be noted inside the page-definitions:
page = PAGE
page {
typeNum = 0
config.pageTitle.stdWrap.override.cObject < lib.pagetitle_1
...
}
anotherPage = PAGE
anotherPage {
typeNum = 1
config.pageTitle.stdWrap.override.cObject < lib.pagetitle_2
...
}
Below still a lib.pagetitle which makes a little bit more than only using title or subtitle - it uses news-title if the extension is used on a page:
lib.pagetitle = COA
lib.pagetitle {
10 = TEXT
10 {
// subtitle: used as field for title tag
value.field = subtitle // title
if.isFalse.data = GP:tx_news_pi1|news
}
20 = RECORDS
20 {
if.isTrue.data = GP:tx_news_pi1|news
dontCheckPid = 1
tables = tx_news_domain_model_news
source.data = GP:tx_news_pi1|news
source.intval = 1
conf.tx_news_domain_model_news = TEXT
conf.tx_news_domain_model_news {
field = title
htmlSpecialChars = 1
}
}
}
Now still some background why I think some individual header might not be the best solution:
TYPO3 usually adds several details to the header, that are useful and it's not required to combine those things individually new.
Scripts and stylesheets are organized and can be even by TypoScript compressed and merged. If some syntax is followed it even takes care that a library like jquery is only included once.
TYPO3 has many functions in TypoScript where everything can be defined related to the header and also it can be decided if scripts shall be perhaps never be included at all in the header but instead in the bottom of the page-source.
Metatags can be defined (and overridden by extensions or sub-templates)
Implementing this whole logic manually again in an own template in my opinion is not useful and I think headers should be only disabled for special page-types like AJAX or dynamic PDF-files. This is the primary reason that I consider that option as useful.
Her still the current link for the most recent documentation about the config-options in TypoScript (anchor pagetitle):
https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/Index.html#pagetitle