How to access "layout"-field inside gridelements - typo3

In a installation of Typo3 7.6, I have a simple gridelement, just providing two columns.
When adding a gridelement in the backend, I can set appearence -> layout to one of several values.
The configuration of gridelements via typoscript adds its values to tt_content.gridelements_pi1.20.10.setup
Is there a possibility to add a class to the typoscript-setup, depending on the value in "layout"?

Since the value belongs to the grid container itself, there is no special magic necessary to get it from the record. A simple dataWrap should do the job.
tt_content.gridelements_pi1.20.10.setup {
1 < lib.gridelements.defaultGridSetup
1 {
dataWrap = <div class="layout-number-{field:layout}">|</div>
columns {
...
}
}
}

Related

TYPO3 FLUIDTEMPLATE How to switch between different backend layouts and only switch between the templates, not the layouts?

I have following Typoscript for switching backend layout:
10 = FLUIDTEMPLATE
10 {
templateName = TEXT
templateName {
cObject = TEXT
cObject {
data = pagelayout
required = 1
case = uppercamelcase
split {
token = pagets__
cObjNum = 1
1.current = 1
}
}
ifEmpty = Default
}
templateRootPaths {
0 = EXT:package/Resources/Private/Templates/Page/
1 = {$page.fluidtemplate.templateRootPath}
}
partialRootPaths {
0 = EXT:package/Resources/Private/Partials/Page/
1 = {$page.fluidtemplate.partialRootPath}
}
layoutRootPaths {
0 = EXT:package/Resources/Private/Layouts/Page/
1 = {$page.fluidtemplate.layoutRootPath}
}
...
My goal is: I have different backend layouts, like 2 columns, three columns...
When I switch, I want to load 2Columns.html or 3Columns.html from the Resources/Private/Templates/Page/, but keep the Default.html (Main Layout of the Website) in Resources/Private/Layouts/Page/. But I always get the error:
The Fluid template files "/package/Resources/Private/Layouts/Page/2Columns" could not be loaded.
How can I achieve this?
Thanks!
The naming might be misleading.
There are a lot of templates in the world of TYPO3:
there are typoscript configurations which are called template. These consists of records (table sys_template) or files (*.typoscript)
there are HTML-files which includes pattern how the page should be generated (classical HTML-template)
2.a. there are marker-templates for the old way
2.b. there are FLUID-templates. These are divided into three categories which are stored in separate folders named for their purpose:
2.b.I. Templates
2.b.II. Partials
2.b.III. Layouts
And with category 2.b.I. we get another template.
If you use FLUID the primary decision for an appearance of a page is done with the template you start with.
Also that is the only entry in selecting any FLUID files.
Inside this selected template file (= from the folder Templates/) you can select a layout file. With this concept you can have different appearances (e.g. one-, two-, three-columns) with common parts like header/ footer.
In the layout file you define those parts of a page which are common to different templates.
In the partial files you define smaller parts which can be used multiple times or which just make a separate unit (e.g. a menu, or the way you want to include images)
The other non unique name is layout:
Inside the FLUID templates we had the category layout(2.b.III)
but there also are fields in some records named layout: tt_content.layout, pages.layout, pages.backend_layout, pages.backend_layout_next_level
These can make a difference in the appearance of the data.
But that must be configured.
Your example uses pagelayout which gets filled from the fields pages.backend_layout, pages.backend_layout_next_level with inheritance and override, so you can easily use it. and correctly you select a (FLUID-)template.
So: your definition is correct.
You can not select FLUID-layouts from typoscript and you do not need it.

TYPO3 inline fluid condition and typoscriptObjectPath

I search for a solution for inline fluid condition and typoscriptObjectPath.
work fine:
<f:cObject typoscriptObjectPath="lib.currentDate" />
work fine:
<f:if condition="{price.day} == {f:cObject(typoscriptObjectPath:'lib.currentDate')}">
<f:then>work</f:then>
<f:else>dont work</f:else>
</f:if>
work fine:
{f:if(condition:'{price.day} == \'Sunday\'',then:'active',else:'test')}
DONT work
{f:if(condition:'{price.day} == \'{f:cObject(typoscriptObjectPath:'lib.currentDate')}\'',then:'active',else:'test')}
how can i use the right inline code?
You do not need to resolve lib.currentDate cObject within your view, as you can just copy its output into fluid variable. It will avoid any problems with nested quotes, brackets etc. etc... Of course I assume, that's in combination with fluid template of the PAGE:
lib.currentDate = TEXT
lib.currentDate {
data = date:U
strftime = %A
}
page = PAGE
page {
# ....
10 = FLUIDTEMPLATE
10 {
# ....
variables {
mainContent < styles.content.get
currentDate < lib.currentDate
}
}
}
so you can use it in condition just like:
<f:if condition="{price.day} == {currentDate}">That's today!</f:if>
<!-- or... -->
{f:if(condition:'{price.day} == {currentDate}', then: 'active', else: 'not-active')}
Of course if you're working in the plugin's context, you can do the same with assign method within your action, like:
$this->view->assign('currentDate', strftime('%A',date('U')));
Note you have also other options:
Create custom if ViewHelper, which will be useful when price.day and currentDate are different types and requires type conversion before comparison.
Create transient field in your price model, which' getter compares day field with strftime('%A',date('U')) and return boolean value, so you can use it directly as:
<f:if condition="{price.myTransientField}">Hooray!</f:if>

Typo3: Constant as Page UID

I have a list of constants assigned to various page IDs (e.g. myConstant = 22). Now I'd love to replace the following link
<f:link.page pageUid="22" >Link</f:link.page>
with something like
<f:link.page pageUid="{myConstant}" >Link</f:link.page>
I haven't been able to find the right syntax to do so. Any help?
i think you can't access the constants directly but you can use the constants in the ts-setup.
with plugin.tx_myplugin.settings.myPid = {$myConstant} in the ts-setup you can access the pid in your plugin with {settings.myPid}
if you're not using a plugin but a TS FluidTemplate you can assign it them like this:
page = PAGE
page {
10 = FLUIDTEMPLATE
10 {
file = fileadmin/templates/Home.html
variables {
pidList {
myConstant = {$myConstant}
myConstant2 = {$myConstant2}
}
}
}
}
<f:link.page pageUid="{pidList.myConstant}" >Link</f:link.page>
If you are using a FLUIDTEMPLATE typoscript-Object, you can do it as follows in TypoScript:
lib.output = FLUIDTEMPLATE
lib.output {
# ...
variables {
myPageID = {$myConstant}
}
# ...
}
In the fluid-template you can use the variables like you want:
<f:link.page pageUid="{myPageID}" >Link</f:link.page>
In case the template is rendered by an extension in a controller action, you can assign the value to a setting of your plugin: plugin.tx_<extkey>[_pi1].settings.myPageID = {$myConstant}. Then you can use it in the fluid template like this:
<f:link.page pageUid="{settings.myPageID}">Link</f:link.page>
In any case, you can assign that value to some TypoScript Object and read that in your template by either using the f:cObject ViewHelper or the v:var.typoscript ViewHelper from the extension vhs.
I tried something like that in t3 7.6 If you want to use a ts constant (defined in ts-constants field as oneConst) somewhere in your page fluid template you must do somthing like this:
page.10 = FLUIDTEMPLATE
page.10 {
variables{
const_one=TEXT
const_one.value={$oneConst}
}
}
}
Without the TEXT definition you will not get the value. Access it in your template:
{const_one}
Hint: i was not able to organize const in an array. Like
const{
one=TEXT
one.value={..}
}

TYPO3: How can I access property of objects in a partial or section?

I have an object defined in TypoScript
page.10 {
variables {
myObject = COA
myObject{
1 = TEXT
1.value = yome Text
2 = TEXT
2.value = 42
}
}
}
and I need the data of the myObject in a partial
<f:render partial="myPartial" arguments="{content:myObject}" />
that looks like
<section id="myPartial">
<h2>{content.1}</h2>
<p>{content.2}</p>
</section>
Although the content is there ( because {content} will display all the properties) I cannot access it and h2 and p will be empty...
What should I do to fill h2 and p with the content of myObject?
That is not possible. TypoScript only returns text strings at the moment, not arrays. Thus the variable myObject contains the whole concatenated string of the COA, thus yome Text42.
Note that COA means Content Object Array, but the whole COA is one single object that is returned as one string.
Alternative: use the VHS extension's v:var.typoscript ViewHelper:
{namespace v=Tx_Vhs_ViewHelpers}
{v:var.typoscript(path: 'page.10.variables.myObject') -> v:var.set(name: 'myObject')}
After which you can access {myObject.1} etc. in your template. Note that the so-called "chained" usage of v:var.set is optional, but will make it easier to access your variables using an intermediate template variable instead of more expensive calls to retrieve the value completely in multiple locations. The other way:
{v:var.typoscript(path: 'page.10.variables.myObject.1')}
{v:var.typoscript(path: 'page.10.variables.myObject.2')}
etc.
VHS extension on TER: http://typo3.org/extensions/repository/view/vhs

The concept of an object variable in typoscript

In my typoscript 20.special.value and 10.value.typolink.parameter have the same value, which is a page id. I use this value to build a heading and a menu of its subpages within the same COA object. I would like to be able to re-use this value.
How can I call a object property in typoscript?
Here's what I have tried:
10 = HTML
10 {
value.typolink {
parameter = {$temp.LANDINGPAGEMENU.20.special.value}
}
}
UPDATE:
I am re-utilizing my COA object in different parts of the site, and changing only the special.value, so to display a menu I have:
temp.LANDINGPAGEMENU.10.value.typolink.parameter = 2427
temp.LANDINGPAGEMENU.20.special.value = 2427
temp.COLUMN_NOTSURE < temp.LANDINGPAGEMENU
I am after a cleaner way of handling the
temp.LANDINGPAGEMENU.10.value.typolink.parameter = 2427
temp.LANDINGPAGEMENU.20.special.value = 2427
Full LANDINGPAGEMENU typoscript code is http://pastebin.com/p9kPuZEe
Use the constants but not in a way you tried. You have to define the constant first.
Constants: my_constant = 2427
Setup: parameter = {$my_constant}
...OR...
Assign one of the values by reference using the =< operator. However, this would work only when using the whole object. Example:
temp.something = TEXT
temp.something.value = 2427
...parameter.cObject =< temp.something
I suggest you go with the option 1 using the constants as the 2nd option is somewhat cumbersome.
You can copy the property but not by reference it.