TYPO3: pass variable to typoscript via cObject? - typo3

I would like to create a dropdown login form in my menu, like in this example: http://bootsnipp.com/snippets/featured/fancy-navbar-login-sign-in-form
I have this cObject that calls typoscript for the navigation:
<f:cObject typoscriptObjectPath="menu.navbar" />
I need to get the content of the login form somehow into the menu typoscript. Is it maybe possible to pass a variable (in my case the login form) to typoscript via cObject ?

f:cObject has a data Attribute, that can take different kind of values.
Usually the data attribute takes an array and you then can use those values to render content objects using the .field properties in typoscript.
An example:
lib.testFluid = COA
lib.testFluid {
wrap = <div>|</div>
10 = TEXT
10.field = title
10.wrap = <b>|</b>
20 = TEXT
20.field = content
}
If you have TypoScript like that, a data array, that has the keys title and content is expected. Rendering such a content object would possibly look like this in fluid:
<f:cObject typoscriptObjectPath="lib.testFluid" data="{title: 'Hello World', content: 'Foobar'}" />
However, if you just have some "content" (e.g. string content) and want to output it at one place in your content object, you can pass it in as-is and use the .current property in TypoScript to let it use the "current value".
lib.testFluid = COA
lib.testFluid {
wrap = <div>|</div>
10 = TEXT
10.current = 1
10.wrap = <b>|</b>
}
And in fluid:
<f:cObject typoscriptObjectPath="lib.testFluid" data="simple text content" />
or
<f:cObject typoscriptObjectPath="lib.testFluid">simple text content</f:cObject>
Of course data also takes normal variables. Depending on your use case, one of those cases might be what you want.
Edit: However, it seems to be a bit more complicated, if you want to use data together with an HMENU. The nested TMENU instances (or other menus) have different data values because it's being overwritten by HMENU with the current page for that menu entry. You probably have to do some convoluted wrapping, or avoid inserting the desired content in a TMENU/GMENU et cetera. I suggest to instead render the menu completely with fluid in that case.
Edit 2 - Example
Something like this is not going to work:
lib.testFluid = HMENU
lib.testFluid {
special = directory
special.value = 1
wrap = <ul>|</ul>
1 = TMENU
1 {
NO.stdWrap.cObject = COA
NO.stdWrap.cObject {
10 = TEXT
10.field = title
10.noTrimWrap = || |
20 = TEXT
20.current = 1
}
}
}
20.current = 1 won't include the value from data supplied by the fluid viewhelper, because the "data" of TMENU has been changed to the current page by the HMENU content object.
However, it should be possible to wrap a COA or similar around the HMENU to insert the desired content somewhere around the HMENU.

Related

TYPO3 Wrap two columns?

In the template setup I have set two columns up like this:
column1 < styles.content.get
column1.select.where = colPos = 1
column1.stdWrap {
wrap = <div>|</div>
required = 1
}
column2 < styles.content.get
column2.select.where = colPos = 2
column2.stdWrap {
wrap = <div>|</div>
required = 1
}
This wraps the column with a div but only if there is something in it.
Is there a way to put a wrap around BOTH columns if at least one of them has content?
At the moment I am achieving this using CSS :empty {display:none;} on the wrap in the template partial, but I would rather do it in Typoscript because :empty is not supported everywhere.
The clean solution would be:
Either you define a COA in typoscript:
column_1_and_2 = COA
column_1_and_2.10 < .column1
column_1_and_2.20 < .column2
column_1_and_2.wrap = <div>|</div>
or you use a little bit of logic in your fluid:
<f:if condition="{column1}{column2}">
<div>
{column1->f:format.raw()}
{column2->f:format.raw()}
</div>
</f:if>
DON'T try to build logic with splitted wraps.

typoscript: do not show submenu if certain backend_layout is selected

I made a special panning sub menu with icons which can be inserted choosing a specific backend_layout named pagets__panmenu , if that layout is selected the main menu should not display a sub menu and link to the page instead of opening a sub ...
I work with typo3 V7.6.11 and fluid styled content
The part reading the value works correctly:
NO = 1
NO {
before.cObject = LOAD_REGISTER
before.cObject{
panmenu.cObject = TEXT
panmenu.cObject.data.dataWrap = DB:pages:{field:uid}:backend_layout
}
ATagBeforeWrap = 1
wrapItemAndSub = <li>|</li>
stdWrap.htmlSpecialChars = 1
}
This is my best effort to match, but its not working:
IFSUB <.NO
IFSUB {
wrapItemAndSub = <li class="dropdown">|</li>
wrapItemAndSub.override = <li>|</li>
wrapItemAndSub.override.if {
value.data = register:panmenu
equals = pagets__panmenu
}
ATagParams = class="dropdown-toggle" data-toggle="dropdown"
ATagBeforeWrap = 1
}
I know that also the 2 < .1 has to be suppressed, I'm trying to get the if to work to keep the style and link clean for starters ...
First of all: have you set TMENU.IFSUB = 1?
Else, everything you do in IFSUB won't have an effect.
Now some general thoughts:
a) Normally, backend layouts are used to switch an entire page template:
page.10 = FLUIDTEMPLATE
page.10 {
file.stdWrap.cObject = CASE
file.stdWrap.cObject {
key.data = pagelayout
default = TEXT
default.value = {$myTemplatePath}/Standard.html
1 = TEXT
1.value = {$myTemplatePath}/Home.html
2 = TEXT
2.value = {$myTemplatePath}/Landing.html
}
layoutRootPath = {$myLayoutPath}
partialRootPath = {$myPartialPath}
}
So this initiates the frontend rendering for the entire page, where backend_layout with uid 1 will use the Home.html template, backend_layout with uid 2 will use the Landing.html template, and all others (=default) will use the Standard.html template.
If you build your site by this method, I would recommend doing
# that's the original version of your menu
lib.panmenu = HMENU
lib.panmenu {
// ...
}
# make a copy of the original
lib.panmenu_variant < lib.panmenu
# modify it as required
lib.panmenu_variant.1.NO {
// ...
}
Now, in your page Templates (which you call separately via the CASE from above), you can either use
<f:cObject typoscriptObjectPath="lib.panmenu" />
or
<f:cObject typoscriptObjectPath="lib.panmenu_variant" />
b) But if you don't want to follow that approach, you should also be able to use the backend_layout CASE on any cObject. The CASE variant has proven much more robust for me.
Here' how I'd try to get the CASE working (untested!)
// suppose temp.navigation_main is your full menu
temp.navigation_main_variant < temp.navigation_main
temp.navigation_main_variant {
// modify the menu as you please
10.2 >
10.1.IFSUB.wrapItemAndSub = <li>|</li>
}
// use lib.nav in your page
lib.nav = CASE
lib.nav {
key.data = pagelayout
// normally, lib.nav is the full navigation
default < lib.navigation_main
// except if be layout 1 is selected
1 < lib.navigation_main_variant
}
}
c) I've tried TypoScript constructions with LOAD_REGISTER and ifs years ago and they always made me go crazy. I wouldn't invest too much energy into them, as they rather seem to be legacy parameters than the future way of development for TYPO3 logic.

TYPO3 7.4 display categories

I'm trying to display the categories of the current page.
Because I'm not that good in TYPO3, I first tried displaying all the categories before trying to display the current one.
The following snippet somehow doesn't work.
lib.categorized_content = RECORDS
lib.categorized_content {
categories.field = selected_categories
categories.relation.field = category_field
tables = tt_content
conf.tt_content = TEXT
conf.tt_content {
stdWrap.field = header
stdWrap.typolink.parameter = {field:pid}
stdWrap.typolink.parameter.insertData = 1
stdWrap.wrap = <li>|</li>
}
wrap = <ul>|</ul>
}
This is where I got this snippet from: https://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Records/Index.html#categories
I'm using <f:cObject typoscriptObjectPath="lib.categorized_content" /> to implement it into my template.
Can someone help?
selected_categories and category_field are flexform field (as you can see from the suffix .field of the configuration property) from the Special Menu content element.
You have to replace those with the actual value.

Subpage Links with image and text

I try to implement a page which contains images to certain subpages. For each subpage, I have a seperate image. I want to display for each subpage the appropriate image "galerie_XX.png" an show the name of the subpage above the image. So far I got:
galerielabel = HMENU
galerielabel.special = directory
galerielabel{
1 = TMENU
1.NO.stdWrap{
wrap = <img src="fileadmin/templates/images/galerie/galerie_|.png" />
}
}
The Subpages are year names, like 2012, 2013... This script shows me the required images as a link.
My question is, how can I add the name of the subpages above the image?
Thank you in advance.
I suggest a different approach.
You can add images in the page properties.
Then, your menu could be like this:
lib.menu = COA
lib.menu.10 = HMENU
lib.menu.10 {
10 = HMENU
10.1 = TMENU
10.1.NO.doNotShowLink = 1 #will remove the link altogether
10.1.NO.before.cObject = COA
10.1.NO.before.cObject {
10 = TEXT
10.field = title #title of the page, change to any field you like
20 = IMAGE
20.file.import = uploads/media/ #4.x style
20.file.import.field = media
20.file.import.listNum = 0 #use first image referenced
20.width = 200 #set to imagesize of your liking
30 = TEXT
30.value = Do what you like here
}
}
Untested: the title of the page should be prepended
galerielabel = HMENU
galerielabel.special = directory
galerielabel{
1 = TMENU
1.NO.stdWrap{
# Prepend with page.title
prepend = TEXT
prepend {
field = title
htmlSpecialChars = 1
}
wrap = <img src="fileadmin/templates/images/galerie/galerie_|.png" />
}
}

"Menu of subpages" doesn't work in a Typo3 Fluid template while fetching a record from a page

I'm trying to add a "user controlled" footer in the main layout of a Typo3 Fluid based template.
This means that I've added a backend layout with four columns in a special back-end page called "footer page". A user is able to add content elements in those columns using the WEB > PAGE module.
Whenever a user adds a content element (text, text w/images, bullet lists, etc...) in one of the columns, everything works and the content is correctly displayed.
But when the user tries to add a special menu content element, the menu isn't displayed and the column container stays empty.
the main layout
<body>
...
<div id="footer">
<f:cObject typoscriptObjectPath="lib.footer" />
</div>
</body>
main PAGE typoscript
page = PAGE
page {
# Regular pages always have typeNum = 0
typeNum = 0
10 = FLUIDTEMPLATE
10 {
#file = {$filepaths.templates}index_f.html
partialRootPath = {$filepaths.templates}partials/
layoutRootPath = {$filepaths.templates}layouts/
variables {
...
footer < lib.footer
...
}
}
}
lib.footer typoscript
lib.footer = COA
lib.footer {
10 = CONTENT
10 {
table = tt_content
select.pidInList = {$contentpage.footerPID}
select.where = colPos = 901
select.orderBy = sorting
stdWrap.wrap = <div id="footer-widget-1" class="col205">|</div>
}
20 = CONTENT
20 {
table = tt_content
select.pidInList = {$contentpage.footerPID}
select.where = colPos = 902
select.orderBy = sorting
stdWrap.wrap = <div id="footer-widget-2" class="col205">|</div>
}
...
}
Am I doing something wrong or is it a bug?
Typo3 version is 6.0.4
You may want to have a look at the VHS extension for TYPO3 - it contains one ViewHelper in particular which would let you render content elements from any column on any page (by UID). It can even render content elements from a list of content element UIDs (which you could specify in TypoScript, select in a FlexForm, make editable in the constants editor etc.):
http://fedext.net/viewhelpers/vhs/Content/RenderViewHelper.html
Many times the ViewHelpers from VHS will let you do exactly the same as TS lets you do, but do so directly in Fluid and with the option to manually control the HTML that is output.
Cheers,
Claus aka. NamelessCoder