How to assign two instances of the same plugins to different markers in a template - typo3

I need to insert two instances of tt_news on the same page and assign each instance of the plugin to a marker in the template. The two instances would be inserted in a backend column not rendered by my template, like border.
Since inserted plugins have a visible id on the backend, I was thinking about something like this
page.10.marks.NEWS1 < plugin.tt_news.idxxx
page.10.marks.NEWS2 < plugin.tt_news.idyyy
How can I achieve this ?

Hm... You could either insert content elements at the marker, like so
temp.contentElement = RECORDS
temp.contentElement {
tables = tt_content
dontCheckPid = 1 # if necessary
}
page.10.marks.NEWS1 < temp.contentElement
page.10.marks.NEWS1.source = UID_OF_NEWS_PLUGIN_ELEMENT
or, you could simply completely configure the plugin in ts
temp.news1 < plugin.tt_news
temp.news1 {
# configure
}
temp.news2 < plugin.tt_news
temp.news2 {
# configure
}
page.10.marks.NEWS1 < temp.news1
Hope that helps

Related

TYPO3: configure available types for tx_news content element relation

Is it possible to configure which content element types are available for the content elements relation in tx_news records?
I have a backend layout which allows only gridelements in tt_content. The regular content elements are only allowed within a grid elements container.
Currently I face the problem, that in news records it's only possible to add grid elements:
I'd like to allow only some specific content elements in news records.
Update:
The above mentioned restriction is done via TSConfig for the BackendLayout:
mod.web_layout.BackendLayouts {
1 {
title = Standardseite
config {
backend_layout {
colCount = 1
rowCount = 1
rows {
1 {
columns {
1 {
name = Content
colPos = 0
allowed = gridelements_pi1
}
}
}
}
}
}
}
}
When I remove the line allowed = gridelements_pi1, all content element types are available again.
But regardless of the allowed setting for backend layouts I'd like to have just a small subset of content element types available for news records.
Sometimes the solution can be so simple and obvious! Thx for hint, Georg Ringer!
Just override the settings for the news sys folder:
[45 in tree.rootLineIds]
# this changes the allowed CTypes. Add more as a comma separated list
mod.web_layout.BackendLayouts.1.config.backend_layout.rows.1.columns.1.allowed = textmedia
# this sets the default CType to prevent an error with INVALID VALUE ("text")
TCAdefaults.tt_content.CType = textmedia
[global]
By the way, an even better solution would be to use TCEFORM.tt_content.CType.removeItem = ..., but this would require to update the list each time you add a new CType.

How to limit showPrevNext in news to categories?

In the TYPO3 CMS 9.5.18 LTS with tx_news 8.3.0 we use the following extension Typoscript:
plugin.tx_news.settings{
# what is allowed to overwrite with TS
overrideFlexformSettingsIfEmpty := addToList(categories)
overrideFlexformSettingsIfEmpty := addToList(categoryConjunction)
# ids of categories
categories = 3
# category conjunction mode
categoryConjunction = or
}
I wonder why I have to add categories to overrideFlexformSettingsIfEmpty to get the result below. Never the less this post is more about how to achieve that the prev/next links (settings.detail.showPrevNext) does respect the category definition at all.
Our customer has 3 categories for news. If I go to a single page that does has a one category limitation (for the detail and the list page) I still e.g. can go "forward" to newer news in a total different category. However the list page only shows the news of that one selected category.
<f:if condition="{paginated.prev}">
<n:link newsItem="{paginated.prev}" settings="{settings}" class="ts-prev">
{paginated.prev.title}
</n:link>
</f:if>
Wasn't that never the case? Do I have to add some Typoscript or make a change in Fluid? The original code uses this settings variable as argument which contains the category limitation.
Okay I've had a look into the GeorgRinger\News\ViewHelpers\SimplePrevNextViewHelper and there aren't any limitation for the current chosen categories.
So here is what I did:
register a new optional argument categories to the viewhelper
add categories="{settings.categories}" to the simplePrevNext tag in the Detail.html
add an 'extra where' for the main query in the getNeighbours function
add the content for the additional where ( I did that first in the getNeighbours function )
Extra where:
if( is_array($newsOfCategory) && count($newsOfCategory) > 0 ){
$extraWhere[] = $queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter($newsOfCategory, Connection::PARAM_INT_ARRAY));
}
Content for the additional where:
if( is_string($categories) && preg_match('/^[0-9]+(,[0-9]+)*$/',$categories) ){
$categories = explode(',', $categories);
$tmpCon = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_category_record_mm');
$tmpQB = $tmpCon->createQueryBuilder();
$rows = $tmpQB
->select('uid_foreign')
->from('sys_category_record_mm')
->where(
$tmpQB->expr()->in('uid_local', $tmpQB->createNamedParameter($categories, Connection::PARAM_INT_ARRAY))
)
->andWhere(
$tmpQB->expr()->like('tablenames', $tmpQB->createNamedParameter('tx_news_domain_model_news'))
)
->execute()->fetchAll();
if( is_array($rows) && count($rows) > 0 ){
foreach($rows as $row){
$newsOfCategory[] = $row['uid_foreign'];
}
}
}
May be someone can use that in the future or the will integrate that to the repository.

How to use Page Ids retrieved from Database in the HMenu?

I'm currently working on my first typo project and need to create a mega menu with an individual set of pages.
Many attempts failed or are not suitable for me. My current shot aims to group pages of the redirect type in a hidden page. In Typoscript I want to set the ID of the parent page containing these redirections and read the shortcut IDs of the children accordingly.
pageIds = CONTENT
pageIds {
table = pages
select {
selectFields = shortcut
pidInList = 614 # Id of the container Page
}
}
The next step would be to use the retrieved shortcut IDs in my HMENU of the type 'list'.
1 = HMENU
1 {
special = list
special {
value = # Assign retrieved IDs here
}
[...]
}
Typoscript is very confusing at first sight, so I would be glad to receive some hints how I can transfer the query's result, as a comma-seperated list, to the HMENU.
Thanks in advance!
Greetz.
First, you need to get a comma-separated list of the page UIDs you want to link. This can be achieved with a renderObj:
lib.pageIds = CONTENT
lib.pageIds {
table = pages
select {
selectFields = shortcut
pidInList = 614 # Id of the container Page
}
renderObj = TEXT
renderObj.stdWrap.field = shortcut
renderObj.stdWrap.wrap = |,
}
This should give you a comma-separated list of all records. Now you must apply these to the HMENU. As you can read in the documentation, the value property is stdWrap enabled, this means that you can copy a value when you use a cObject:
1 = HMENU
1 {
special = list
special {
value.cObject < lib.pageIds
}
[...]
}
I didn't test this, so maybe the configuration is not entirely complete.

Typo3: How to render the titles of the backend-columns in Fluid/ExtBase?

I'm not sure if I used the correct terms :D
Let's imagine that my backend-layout looks like this:
backend_layout {
colCount = 1
rowCount = 1
rows {
1 {
columns {
1 {
name = Baguette
colPos = 0
}
}
}
}
}
I'm looking for a TypoScript which looks kinda like this:
[...]
variables {
title < ****the stuff i'm looking for***
title.select.where = colPos = 0
}
The script should automatically take the name of my backend-column ("Baguette") and save it into the "title"-variable.
Then i can simply add <f:format.raw> {title} </f:format.raw> in my template to output it in the frontend.
Does something like this exist?
Btw: It's necessary to be able to select the colPos since I'm having many columns with many titles to output.
This does not exist. The titles are only known to the backend and are not available in the frontend context.
Actually the frontend does not know anything about the backend grid. All you have in the frontend, is the column number.

TYPO3: Special tt_contenttype. Modify content before output

Can I create a "special" type of tt_content, so text is beeing processed in some custom ways before outputtet?
In my case I would like to add ###MY_MARKER### somewhere in header and/or bodytext and have it replaced by the right words for the given page.
eg:
When visiting this page: mypage.com/?marker=test
Header in tt_content: "Welcome to ###MY_MARKER##, enjoy
Output in browser: "Welcome to TEST, enjoy"
I CAN do it by making a custom plugin. Question is more if I can reuse normal tt_contant for the same purpose
Yes, you can easily extend the tt_content by adding your own TCA configuration to the typo3conf/extTables.php file:
t3lib_div::loadTCA('tt_content');
$TCA['tt_content']['columns']['CType']['config']['items']['user_my_type'] = array(
0 => 'My custom content',
1 => 'user_my_type',
2 => 'i/tt_content.gif',
);
$TCA['tt_content']['ctrl']['typeicon_classes']['user_my_type'] = 'mimetypes-x-content-text';
$TCA['tt_content']['ctrl']['typeicons']['user_my_type'] = 'tt_content.gif';
/* In the following either copy, insert and modify configuration from some other
content elemenet (you can find it in the ADMIN TOOLS -> Configuration - $TCA)... */
$TCA['tt_content']['types']['user_my_type']['showitem'] = '';
/* ...or assign it some other configuration so that it's exactly the same
as some other content type and stays the same after some update of TYPO3: */
$TCA['tt_content']['types']['user_my_type']['showitem'] = $TCA['tt_content']['types']['text']['showitem'];
After that, just set in your Typoscript template how the element is supposed to be rendered:
tt_content.user_my_type = COA
tt_content.user_my_type {
10 = TEMPLATE
10 {
template = TEXT
template.field = header
marks {
MY_MARKER = TEXT
MY_MARKER.value = TEST
}
}
20 = TEMPLATE
20 {
template = TEXT
template {
field = bodytext
required = 1
parseFunc = < lib.parseFunc_RTE
}
marks < tt_content.user_my_type.10.marks
}
}
NOTES
The Typoscript rendering is just a simplified example. You might want to add other standard configuration like in other elements, e.g. the one that adds edit icons for frontend display.
The marker in my example can be populated by the value of a GET paramater in the URL as you wanted but this would have nasty security implications. You would certainly need very good validation of that input.