Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set tx_news specific conditions in my typoscript?

for displaying news i´ve made different template layouts to choose for backend editors, configured in my theme´s PageTSconfig:

tx_news.templateLayouts {
        10 = LLL:EXT:mytheme/Resources/Private/Language/locallang.xlf:news.layout.withoutDate
        20 = LLL:EXT:mytheme/Resources/Private/Language/locallang.xlf:news.layout.highlightListView
        30 = LLL:EXT:mytheme/Resources/Private/Language/locallang.xlf:news.layout.imageTeaserListView
    }

In my fluid template i can switch conditions like

<f:switch expression="{settings.templateLayout}">
  <f:case value="10">
  ... use layout 1
  </f:case>
  <f:case value="20">
  ... use layout 2
  </f:case>
  <f:case value="30">
  ... use layout 3
  </f:case>
</f:switch>

Everything works very fine until here.

Now i want to embed javascript for only one of these template layouts. So i tried to include the js within a condition in typoscript, asking for the value in this templateLayout setting. Something like this:

[globalVar = GP:tx_news_pi1|settings|templateLayout=30]
page{
    includeJSFooter {
        test = EXT:mytheme/Resources/Public/JavaScript/news-test.js
    }
}
[global]

But this condition does not work. So my question: What is wrong? And how can i manage this to work, to get the right value for the condition? I hope anyone can help, thanx in advance.

like image 889
Mirko Avatar asked Mar 11 '23 22:03

Mirko


1 Answers

The condition [globalVar = GP:tx_news_pi1|settings|templateLayout=30] refers to data that has been sent using an HTTP request which is not the case in that regard. settings are part of the TypoScript and FlexForm part inside the plugin element that has been created in the TYPO3 backend.

My suggestion is to extend your Fluid templates and load the accordant resource there. You could use an additional setting pointing to the file as well.

New TypoScript setting for news:

plugin.tx_news.settings.Mytheme {
    customLibrary = EXT:mytheme/Resources/Public/JavaScript/news-test.js
}

Access inside Fluid:

{namespace n=GeorgRinger\News\ViewHelpers}

<f:switch expression="{settings.templateLayout}">
  <f:case value="10">
  ... use layout 1
  </f:case>
  <f:case value="20">
  ... use layout 2
  </f:case>
  <f:case value="30">
  ... use layout 3
  <n:includeFile path="{settings.Mytheme.customLibrary}" />
  </f:case>
</f:switch>

The example above uses the IncludeFileViewHelper of EXT:news

like image 103
Oliver Hader Avatar answered Mar 23 '23 17:03

Oliver Hader