How to apply a different wrap in a TMENU for certain items only? - typo3

In a TMENU, I would like to apply a special wrap to certain pages only.
So of
Home
-- This
-- That
-- Such
-----A
-----Thing
Only the page "Such" would have this wrap (with a special class or an icon for wrapItemsAndSub).
Ideally, this could be done from the page tree / from the CMS. Or by pid.
But I think it's not possible to reach into the TMENU in an easy way?
OptionSplit is not an option, as it's only a few special pages.
Can this be done and how?

You must use CASE object here and apply that to property/wrap which has stdWrap.
Look at this example.
NO {
wrapItemAndSub.cObject = CASE
wrapItemAndSub.cObject {
key.field = uid
default = TEXT
default.value = <li>|</li>
// for page uid = 99
99 = TEXT
99.value = <li class="special">|</li>
}
}
You can use this way to every element that has stdWrap.

BTW: as pgampe said it can be of course done more universal with some checkbox or even dropdown when you select class name.
This is a short tutorial for checkbox. For this tutorial I assume the extension name is "t3_local"
STEP 1
In ext_tables.sql file add:
CREATE TABLE pages (
tx_t3local_special tinyint(4) DEFAULT '0' NOT NULL,
}
Then go into Extension Manager into your extension and update database to create the new field in pages table.
STEP 2
In ext_tables.php file add:
$tempColumns = Array(
'tx_t3local_special' => Array(
'exclude' => 1,
'label' => 'Some label for special',
'config' => Array(
'type' => 'check',
'default' => 0
)
)
);
t3lib_div::loadTCA('pages');
t3lib_extMgm::addTCAcolumns('pages', $tempColumns, 1);
t3lib_extMgm::addToAllTCAtypes('pages', 'tx_t3local_special');
It is ready now to use in the backend. After you clear the TYPO3 cache you should see the checkbox in page properties. Now we must only use it to build our menu in frontend.
STEP 3
Now it all depends what do you want to do with this switch. Assuming that you want to add a class for li here is a little trick how to allow to use several such switches to accumulate different classes.
NO.wrapItemAndSub.stdWrap {
prepend.cObject = LOAD_REGISTER
prepend.cObject {
special1class.cObject = TEXT
special1class.cObject {
value = special1-class
if.isTrue.field = tx_t3local_special
}
special2class.cObject = TEXT
special2class.cObject {
value = special2-class
if.isTrue.field = tx_t3local_special2
}
}
append = TEXT
append.value = <li class="clearfix {register:special1class} {register:special2class}">/li>
append.insertData = 1
}
NOTE
As you now know how to add switches to page property you can also use them to turn off/on some functionality on page. For example I use such switch to turn on/off breadcrumbs for page. In this example the if checkbox is checked the breadcrumb of off.
For this working you must remember to add the field name to typo3conf/localconf.php file (or LocalConfiguration.php in 6.x)
$TYPO3_CONF_VARS['FE']['addRootLineFields'] .= ',tx_t3local_breadcrumb';
And the TS:
lib.breadcrumb = COA
lib.breadcrumb.stdWrap.if.isFalse.data = page:tx_t3local_breadcrumb
lib.breadcrumb {
...
...
...
}

Related

How can I set the icon for a content element in TYPO3?

In tt_content I have added something like this, and set the core icon 'content-image':
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'My Element',
'myelement',
'content-image'
],
'textmedia',
'after'
);
And this works in the 'Type' dropdown menu. However, when in Page or List view it always shows the default text icon. How do I change this to match the type menu?
Just found another question with a real good answer - mainly the same
as mine, but better structured - have a look:
How to setup icons for content elements or plugins in a TYPO3 extension
You may revisit https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentElements/AddingYourOwnContentElements.html with a full overview.
The \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem() registers the icon only for the select field.
For the "new content element" wizard you have to provide a proper TSconfig part https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentElements/AddingYourOwnContentElements.html#add-it-to-the-new-content-element-wizard
// example - you must adopt for your element
mod.wizards.newContentElement.wizardItems {
// add the content element to the tab "common"
common {
elements {
examples_newcontentelement {
iconIdentifier = content-text
title = LLL:EXT:examples/Resources/Private/Language/locallang.xlf:examples_newcontentelement_title
description = LLL:EXT:examples/Resources/Private/Language/locallang.xlf:examples_newcontentelement_description
tt_content_defValues {
CType = examples_newcontentelement
}
}
}
show := addToList(examples_newcontentelement)
}
}
If you want to use a custom image, you have to register it. Either in ext_localconf.php with proper icon calls or depending on the core version with the simple Configuration/Icons.php file.
See for 11.5+ https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Icon/Index.html or before see https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/Icon/Index.html
The next part is then TCA configuration for the specific table. Generic table icon file is configured with:
// or $GLOBALS if done as TCA Override for a existing table
return [
// ...
'ctrl' => [
'iconFile' => '',
// ...
],
// ...
https://docs.typo3.org/m/typo3/reference-tca/main/en-us/Ctrl/Properties/Iconfile.html
Table with types can have different icons per types, which can be set with typeicon_classes
https://docs.typo3.org/m/typo3/reference-tca/main/en-us/Ctrl/Properties/TypeiconClasses.html#ctrl-reference-typeicon-classes - however, this depends on the type field. For tt_content this is "CType". So this helps only for real content elements which registeres as own CType - and not as list CType with a subtype list_type. For extbase plugin this is done with the proper plugin registration in Configuration/TCA/Overrides/tt_content.php:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'ExtkeyInCamelCase',
'PluginIdentifier',
'plugin title',
// icon
'my-icon');

Add custom elements to TYPO3 as hidden by default?

I have an installation with multiple websites. Each site has a site package with custom fields and content elements that are specific to that site.
But the custom fields and content elements are shown on all sites.
In tt_content.php I add a custom element to the type dropdown. How can I make it hidden, then enable it in ts config for the page tree that it is used for?
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'Banner',
'my_extension_banner',
'EXT:core/Resources/Public/Icons/T3Icons/content/content-image.svg'
],
'textmedia',
'after'
);
Likewise, I have some custom fields added to existing elements. How can I make this field hidden unless specifically enabled by the ts config of the page that it is made for?
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
'tt_content',
'headers',
'--linebreak--,my_extension_myfield',
'after:subheader'
);
After some trial and error, I found that I can remove elements and fields globally by adding this to my ext_localconf.php:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('
#Remove Custom Content Elements
TCEFORM.tt_content.CType.removeItems := addToList(my_extension_banner)
#Remove Custom Fields
TCEFORM.tt_content {
my_extension_myfield.disabled = 1
}
');
Then add them in again with my page specific ts config file PageTSConfig.tsconfig
#Add Custom Content Elements
TCEFORM.tt_content.CType.removeItems := removeFromList(my_extension_banner)
#Add Custom Fields
TCEFORM.tt_content {
my_extension_myfield.disabled = 0
}
I don't know if I understand the problem correctly, but you could place Page TsConfig in the root page of any web page and then hide the fields accordingly:
TCEFORM.pages {
subtitle.disabled = 1
}

TYPO3 determine page type of menu item and wrap div with custom class around it

My goal is to apply different navigation logic to different page types. For example shortcut type will be container (drop down list in FE, shortcut itself is dummy link), standard type - page with content that you can navigate to. So, when in FE navigation user selects page:
drop-down list appears
if (type of page in list == standard)
can navigate to page in list;
else if (type of page in list == shortcut)
GO TO drop-down list appears
I know that you can do something like this:
lib {
main-nav = HMENU
main-nav {
1 = TMENU
1 {
expAll = 1
NO = 1
NO.wrapItemAndSub = <li>|</li>
NO.stdWrap.cObject = CASE
NO.stdWrap.cObject {
key.field = doktype
default = TEXT
default {
field = title
}
# standard page type
1 = TEXT
1 {
field = title
wrap = <div>|</div>
}....
As a result you get page title wrapped with div if page type is standard.
But what do i need to do to wrap whole menu item rather then just wrapping title?
If it's just about putting the div around the whole submenu, I guess what you already got should be applied to wrapItemAndSub instead
lib {
main-nav = HMENU
main-nav {
1 = TMENU
1 {
expAll = 1
NO = 1
NO.wrapItemAndSub.cObject = CASE
NO.wrapItemAndSub.cObject {
key.field = doktype
default = TEXT
default {
value = <li>|</li>
}
# standard page type
1 = TEXT
1 {
value = <li><div>|</div></li>
}....
I think you need to combine HTML, CSS and javascript.
In the typoscript you prepare the HTML with different markup depending on page type. Then your javascript has to handle the click event in case of a shortcut page where a click should open a drop down instead of going to that page. (add eventhandler)
So you need to give javascript something to identify the shortcut pages.
With the CASE object you mentioned you can build the apropiate HTML with all neccessary information (you might use data- attributes).
For a more detailed help you need to be more specific what you want to achieve.

How to hide a plugin's title via Typoscript when rendering with css_styled_content

This is probably very basic, but I'm stuck.
In TYPO3 6.1.x with tx_news, I have configured the news detail view to appear on the same page as the list view as taught on http://docs.typo3.org/typo3cms/extensions/news/latest/Main/Tutorial/IntegrationWithTs/Index.html
Also, I have pulled in the news'header as h1 as such
temp.h1 = COA
temp.h1 {
10 = TEXT
10 {
value = <h1>{page:title}</h1>
insertData = 1
}
10 = RECORDS
10 {
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
}
wrap = <h1>|</h1>
}
}
What I couldn't solve yet is that the plugin element has a title (in the regular "header" field). I need to display this header only in the list, but hide that plugin's header field in detail view.
How / where can I do that via page TS?
This is probably not even in the plugin, but in css_styled_content?
Something like this...
[globalVar = GP:tx_news_pi1|news > 0]
plugin.tx_news.stdheader >
[else]
But how?
A plugin is always using this prototype object:
tt_content.list
Therefore you could delete the header of this object like that
tt_content.list.10 >
But if you have other plugins on the same page, their headers would also be deleted. So that would be a bad idea.
I would suggest you use the header_layout field. By default it has an entry called "Hidden" that will hide the header of your plugin. If you don't have it, check the Page TypoScript configuration. You can add own items by using:
TCEFORM.tt_content.headerLayout.addItems.99 = My Header Layout
Then you can then define the rendering of your own layouts in
lib.stdheader.10
(it's a CASE object)

How to change Typo3 Backend layout Name using TypoScript?

By default typo3 Back end layout give Normal,Left,Right and Border.
To hide the blocks i used following code
mod.SHARED.colPos_list = 0,1,2
How to rename the blocks in Typo script:
Normal - Description
Left- News
Right - Publications
Border - Footer
When inserting the following in the Page TSConfig of the root page, the values of the dropdown "Columns" are changed when editing content elements:
TCEFORM.tt_content.colPos.altLabels {
0 = News
1 = Description
2 = Publications
3 = Footer
}
Unfortunately, this is only halfway :(
According to Spalten ändern und umbenennen you'll need to edit typo3conf/extTables.php which affects all pages in the tree:
t3lib_extMgm::addPageTSConfig('
mod.SHARED.colPos_list = 0,1,2,3
');
$TCA["tt_content"]["columns"]["colPos"]["config"]["items"] = array (
"1" => array ("News||||||||||","1"),
"0" => array ("Description||||||||||","0"),
"3" => array ("Publications||||||||||","3"),
"2" => array ("Footer||||||||||","2"),
);
If you're using TYPO3 4.5+, you can use the new feature called backend layout or grid view.
It is very easy to use. You don't have to edit PHP-code. You just have to configure it using a wizard.
Joey Hasenau has written a good article at news.typo3.org about how to use the backend layout.
I hope, this facilitates your daily work!