简体   繁体   English

如果GET var不为空,则TYPO3添加css

[英]TYPO3 add css if GET var is not empty

My goal is quite simple. 我的目标很简单。 If a certain GET parameter is not empty in the URL of the present page I'd like to inject some css to it. 如果某个GET参数在当前页面的URL中不为空,我想向它注入一些css。

In the example bellow I'd like to hide everything (just for example proposes) if the tx_multishop_pi1[page_section] exists in the URL. 在下面的例子中,如果URL中存在tx_multishop_pi1[page_section]我想隐藏所有内容(例如建议)。

page{
  headerData.960= TEXT
  headerData.960.data = GP:tx_multishop_pi1|page_section
  headerData.960.required = 1
  headerData.960.value(
  <style type="text/css">
  body{
    display:none !important;
  }
  </style>
  )       
}

But this isn't working. 但这不起作用。 I could try [globalString = GP:tx_multishop_pi1|page_section = somehting] but I don't want that. 我可以尝试[globalString = GP:tx_multishop_pi1|page_section = somehting]但我不希望这样。 I want to inject css if the tx_multishop_pi1[page_section] var exists (no meter its value) 我想注入css,如果tx_multishop_pi1[page_section] var存在(没有米它的值)

this can be done by using globalString condition and if.isTrue.data 这可以通过使用globalString条件和if.isTrue.data来完成

[globalString = GP:tx_multishop_pi1|page_section > 0]
    page.headerData.960 = TEXT
    page.headerData.960 {
        value (
            <style>
                body{
                   display:none !important;
                }
            </style>
        )
       if.isTrue.data = GP:tx_multishop_pi1|page_section
    }
[end]

You can use userFunc condition (on the bottom of the TSref Conditions ) to perform (almost) any comparison. 您可以使用userFunc条件(在底部TSef文档条件 )来执行(几乎)任何比较。

The most important thing to remember is that this function must to begin with user_ prefix, there are some old docs, which doesn't mention that or gives wrong samples. 要记住的最重要的事情是这个函数必须以user_前缀开头,有一些旧的文档,没有提到或提供错误的样本。 Here's a sample for you (add it to localconf.php ) 这是给你的一个示例(将其添加到localconf.php

function user_multishopSectionExists() {
    $gp = t3lib_div::_GP('tx_multishop_pi1');
    return (is_array($gp) && array_key_exists('page_section', $gp)) ? true : false;
}

So you can use it in the TS setup field: 因此,您可以在TS设置字段中使用它:

[userFunc = user_multishopSectionExists()]
  page.headerData.960= TEXT
  page.headerData.960.value(
    // etc...
  )
[end]

Of course it is better idea to write general matcher ie. 当然最好写一般匹配器,即。 something like: 就像是:

[userFunc = user_paramExists("tx_multishop_pi1|page_section")]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM