在typoscript中测试TMENU

时间:2018-06-04 09:47:32

标签: typo3 typoscript typo3-9.x

我需要在tt_content中存在或不存在内容后更改菜单的外观。为此,我做了这个,但它不起作用,我在测试中有错误:

      1 = TMENU
  1 {
    expAll = 1
    doNotLinkIt = 1                 

    IFSUB = 1
    IFSUB {
       doNotLinkIt = 1

    typeOfMenu = 0 
    #typeOfMenu.override = 1

    # pane content  
    contenu.cObject = COA
    contenu.cObject {                                                                       
          10 = CONTENT
          10 {
            table = tt_content
            select {
              orderBy = sorting
              pidInList.field = uid
              where = {#colPos}=99  and deleted = 0 and hidden = 0
            }
            if.isTrue.data {
                typeOfMenu = 1

            }
           # 20 = TEXT
           # 20 {
           #     field = bodytext
           #     typeOfMenu.value.override.if {
           #         isTrue.data = 20.field
           #     }
           # }
        }
    }
    [globalVar = LIT:1 = typeOfMenu]     
    #[globalVar = LIT:1 = {$typeOfMenu}]
        stdWrap {              
            typolink.parameter.field =  uid
            typolink.ATagParams = class="dropdown shrink" data-toggle="sous-menu{register:count_MENUOBJ}"
            typolink.ATagParams.insertData = 1
        }

    [else]
        stdWrap {              
            typolink.parameter.field =  uid
            typolink.ATagParams = class="vertical menu -- {register:typeOfMenu.value} --"
            typolink.ATagParams.insertData = 1
        }
    [end]            
        ...
  • 错误:第2244行:对象名称字符串," [globalVar"包含无效字符" ["。必须是字母数字或以下之一:" _: - 。"

有没有人有想法? 最好的问候!

几乎是这样,但它不起作用(Bernd Wilke解决方案......)。我不太了解sql查询。并且有一个偏移量,它是第一个为第二个写的ofOfMenu。事实上我想这样:

<div class="top-bar-left">
           <ul class="dropdown vertical menu medium-horizontal" data-responsive-menu="accordion medium-dropdown">
              <li>
                 <a href="/testtypo3-9.2.0/htdocs/index.php?id=25">!</a>
                 <ul class="vertical menu">
                    <li>
                       <a href="/testtypo3-9.2.0/htdocs/index.php?id=29">YogaTissimo.fr</a>
                       <ul class="vertical menu">
                          <li><a href="/testtypo3-9.2.0/htdocs/index.php?id=31">Qui sommes nous ?</a></li>
                          <li><a href="/testtypo3-9.2.0/htdocs/index.php?id=30">Faq</a></li>
                       </ul>
                    </li>
                    <li><a href="/testtypo3-9.2.0/htdocs/index.php?id=28">Vous nous dites ?</a></li>
                    <li><a href="/testtypo3-9.2.0/htdocs/index.php?id=27">Contacts</a></li>
                    <li><a href="/testtypo3-9.2.0/htdocs/index.php?id=26">Â propos</a></li>
                 </ul>
              </li>
              <li>
                 <a href="/testtypo3-9.2.0/htdocs/index.php?id=15">Philosophie</a>
                 <ul class="vertical menu">
                    <li><a href="/testtypo3-9.2.0/htdocs/index.php?id=24">Un art de vivre</a></li>
                    <li><a href="/testtypo3-9.2.0/htdocs/index.php?id=23">Conscience et action</a></li>
                    <li>
                       <a href="/testtypo3-9.2.0/htdocs/index.php?id=17">Journal d'une sadhana [TTC]</a>
                       <ul class="vertical menu">
                          <li><a href="/testtypo3-9.2.0/htdocs/index.php?id=22">Jour 1</a></li>
                          <li><a href="/testtypo3-9.2.0/htdocs/index.php?id=21">Jour 2</a></li>
                          <li><a href="/testtypo3-9.2.0/htdocs/index.php?id=20">Jour 3</a></li>
                          <li><a href="/testtypo3-9.2.0/htdocs/index.php?id=19">Jour 4</a></li>
                          <li><a href="/testtypo3-9.2.0/htdocs/index.php?id=18">Jour 5</a></li>
                       </ul>
                    </li>
                    <li><a href="/testtypo3-9.2.0/htdocs/index.php?id=16">Vedanta</a></li>
                 </ul>
              </li> .....

而且,当colPos = 99中存在某些内容时,我希望:

     <div class="top-bar-left">
        <ul class="dropdown vertical menu medium-horizontal" data-responsive-menu="accordion medium-dropdown">
           <li class="sanskrit-1">
              <a href="/testtypo3-9.2.0/htdocs/index.php?id=25" class="dropdown shrink" data-toggle="sous-menu1">!</a>
              <div class="dropdown-pane" id="sous-menu1" data-dropdown data-options="closeOnClick:true; hover: true; hoverPane: true">
                 <div class="grid-x grid-padding-x">
                    <div class="large-12">PaneC'est-UN_PANE ! </div>
                 </div>
                 <div class="grid-x grid-padding-x">
                    <div class="large-3 medium-4 cell">
                       <p>
                          <a href="/testtypo3-9.2.0/htdocs/index.php?id=29">YogaTissimo.fr</a></br><b>Sur ce site</b>
                          <i>

                       </i></p>
                       <ul class="ssmenu">
                          <li class="first"><a href="/testtypo3-9.2.0/htdocs/index.php?id=31">Qui sommes nous ?</a></li>
                          <li class="last"><a href="/testtypo3-9.2.0/htdocs/index.php?id=30">Faq</a></li>
                       </ul>
                    </div>
                    <div class="large-3 medium-4 cell">
                       <p><a href="/testtypo3-9.2.0/htdocs/index.php?id=28">Vous nous dites ?</a></br></p>
                    </div>
                    <div class="large-3 medium-4 cell">
                       <p><a href="/testtypo3-9.2.0/htdocs/index.php?id=27">Contacts</a></br></p>
                    </div>
                    <div class="large-3 medium-4 cell">
                       <p><a href="/testtypo3-9.2.0/htdocs/index.php?id=26">Â propos</a></br><b></b><i></i>
                       <div class="img-wrap"><img src="/testtypo3-9.2.0/htdocs/fileadmin/user_upload/bg.jpeg" width="225" height="225"   alt="" ></div>
                       </p>
                    </div>
                 </div>
              </div>
           </li>

这里的typoscript部分我很难编码而且有效,没有考虑colPos = 99:

    # menu
20 = HMENU
20 {
    wrap = <ul class="dropdown vertical menu medium-horizontal" data-responsive-menu="accordion medium-dropdown">|</ul>

  # Premier niveau
  1 = TMENU
  1 {
    expAll = 1
    doNotLinkIt = 1                 

    IFSUB = 1
    IFSUB {
       doNotLinkIt = 1

       stdWrap {              
           typolink.parameter.field =  uid
           typolink.ATagParams = class="dropdown shrink" data-toggle="sous-menu{register:count_MENUOBJ}"
           typolink.ATagParams.insertData = 1
        }
        wrapItemAndSub = <li class="sanskrit-1">|</div></div></li> |*| <li>|</div></div></li> |*| <li class="last">|</div></div></li>
        after {
          stdWrap.insertData = 1
          stdWrap.wrap = <div class="dropdown-pane" id="sous-menu{register:count_MENUOBJ}" data-dropdown data-options="closeOnClick:true; hover: true; hoverPane: true"><div class="grid-x grid-padding-x">|

          # pane content  
          stdWrap.cObject = COA
          stdWrap.cObject {                                                                       
          10 = CONTENT
          10 {
            table = tt_content
            select {
              orderBy = sorting
              pidInList.field = uid
              where = {#colPos}=99  and deleted = 0 and hidden = 0
            }

            renderObj = COA
            renderObj {
              10 = TEXT
              10.stdWrap.field = bodytext
              10.stdWrap.wrap = <div class="large-12">|

              20 = FILES
              20 {
                references {
                  table = tt_content
                  uid.data = field:uid
                  fieldName = image
                }
                begin = 0
                maxItems = 1

                renderObj = IMAGE
                renderObj {
                  file {
                    import.data = file:current:originalUid // file:current:uid
                    #width = 232c
                    #height = 145c
                  }
                  required = 1
                  #wrap = <div class="img-wrap">|</div>
                  wrap = |
                }
              }
              30 = TEXT
              30.value = </div></div><div class="grid-x grid-padding-x">
            } //COA
          } //CONTENT
        } //COA
      } //after
    } //IFSUB
  } //1

祝你好运

现在,如果我这样做:

# menu
20 = HMENU
20 {
    wrap = <ul class="dropdown vertical menu medium-horizontal" data-responsive-menu="accordion medium-dropdown">|</ul>

  # Premier niveau
  1 = TMENU
  1 {
    expAll = 1
    doNotLinkIt = 1                 

    IFSUB = 1
    IFSUB {
       doNotLinkIt = 1

        stdWrap.cObject = COA 
        stdWrap.cObject {
            # let's define registers
            1 = LOAD_REGISTER
            # define register 'typeOfMenu'
            1.typeOfMenu.cObject = TEXT
            1.typeOfMenu.cObject {
                # set value 1
                value = 1
                # override with 0
                override = 0
                # override only if this CONTENT is empty
                override.ifEmpty.cObject = CONTENT
                override.ifEmpty.cObject {
                    # select all CEs, from this page in column 99
                    table = tt_content
                    select {
                        pidInList.field = uid
                        where = {#colPos}=99 and deleted=0 and hidden=0
                    }
                    # render only the uid, so even an empty CE will trigger  
                    renderObj = TEXT
                    renderObj.field = uid
                } 
            }
            #99 = RESTORE_REGISTER 
        }                    

        stdWrap.typolink {              
            parameter.field =  uid
            ATagParams = class="vertical menu -- {register:typeOfMenu} --"
            ATagParams.insertData = 1

            ATagParams {
                insertData = 1
                # override the std value: 
                override = class="dropdown shrink" data-toggle="sous-menu{register:count_MENUOBJ}"
                override {
                    insertData = 1
                    # override only if register typeOfMenu is 1
                    stdWrap.if.equals = 1
                    stdWrap.if.data = register:typeOfMenu
                }
            }

        } 




       #stdWrap {              
       #    typolink.parameter.field =  uid
       #    typolink.ATagParams = class="dropdown shrink" data-toggle="sous-menu{register:count_MENUOBJ}"
       #    typolink.ATagParams.insertData = 1
       # }

        wrapItemAndSub = <li class="sanskrit-1">|</div></div></li> |*| <li>|</div></div></li> |*| <li class="last">|</div></div></li>
        after {
          stdWrap.insertData = 1
          stdWrap.wrap = <div class="dropdown-pane" id="sous-menu{register:count_MENUOBJ}" data-dropdown data-options="closeOnClick:true; hover: true; hoverPane: true"><div class="grid-x grid-padding-x">|

          # pane content  
          stdWrap.cObject = COA
          stdWrap.cObject {                                                                       
          10 = CONTENT
          10 {
            table = tt_content
            select {
              orderBy = sorting
              pidInList.field = uid
              where = {#colPos}=99  and deleted = 0 and hidden = 0
            }

            renderObj = COA
            renderObj {
              10 = TEXT
              10.stdWrap.field = bodytext
              10.stdWrap.wrap = <div class="large-12">|

              20 = FILES
              20 {
                references {
                  table = tt_content
                  uid.data = field:uid
                  fieldName = image
                }
                begin = 0
                maxItems = 1

                renderObj = IMAGE
                renderObj {
                  file {
                    import.data = file:current:originalUid // file:current:uid
                    #width = 232c
                    #height = 145c
                  }
                  required = 1
                  #wrap = <div class="img-wrap">|</div>
                  wrap = |
                }
              }
              30 = TEXT
              30.value = </div></div><div class="grid-x grid-padding-x">
            } //COA
          } //CONTENT
        } //COA
      } //after
    } //IFSUB
  } //1

对于&#39; typeOfMenu&#39;我得到了一些价值观(相反,它还没有那么多)。对应于colPos = 99,它几乎是好的,但是不考虑脚本中较低的值。

如果我这样做:

# let's define registers
        stdWrap.innerWrap.cObject = LOAD_REGISTER
        stdWrap.innerWrap.cObject {
            # define register 'typeOfMenu'
            typeOfMenu.cObject = TEXT
            typeOfMenu.cObject {
                # set value 1
                value = 1
                # override with 0
                override = 0
                # override only if this CONTENT is empty
                override.ifEmpty.cObject = CONTENT
                override.ifEmpty.cObject {
                    # select all CEs, from this page in column 99
                    table = tt_content
                    select {
                        pidInList.field = uid
                        where = colPos=99  and deleted=0 and hidden=0
                    }
                    # render only the uid, so even an empty CE will trigger  
                    renderObj = TEXT
                    renderObj.field = uid
                } 
            }
        }

        stdWrap.typolink{              
            parameter.field =  uid
            ATagParams = class="vertical menu -- {register:typeOfMenu} --"
            ATagParams {
                insertData = 1
                # override the std value: 
                override = class="dropdown shrink" data-toggle="sous-menu{register:count_MENUOBJ}"
                override {
                    insertData = 1
                    # override only if register typeOfMenu is 1
                    stdWrap.if.equals = 1
                    stdWrap.if.data = register:typeOfMenu
                }
            }
        }

我明白了:

<li class="sanskrit-1"><a href="/testtypo3-9.2.0/htdocs/index.php?id=25" class="vertical menu -- 46 --">!</a><div class="dropdown-pane" ... # DROP PANE YES
<li><a href="/testtypo3-9.2.0/htdocs/index.php?id=15" class="vertical menu -- 47 --"> ...</a> ... # DROP PANE YES
<li><a href="/testtypo3-9.2.0/htdocs/index.php?id=15" class="vertical menu -- 1 --"> ...</a> ... # NO DROP PANE
<li><a href="/testtypo3-9.2.0/htdocs/index.php?id=15" class="vertical menu -- 1 --"> ...</a> ... # NO DROP PANE
<li><a href="/testtypo3-9.2.0/htdocs/index.php?id=15" class="vertical menu -- 1 --"> ...</a> ... # NO DROP PANE

...

当它是'typeOfMenu&#39; = 1这是我没有droppane但是没有变化:override = class =&#34; dropdown shrink&#34;数据肘节=&#34;苏 -

3 个答案:

答案 0 :(得分:0)

您无法在{ }的块中使用这些TypoScript条件。

e.g。这是不允许的:

lib.test {
    foo = bar

    [globalVar = TSFE:id = 10]
        foo = spam
    [global]
}

而是这样做:

lib.test {
    foo = bar
}

[globalVar = TSFE:id = 10]
    lib.test.foo = spam
[global]

答案 1 :(得分:0)

Typoscript不是编程语言,您可以在其中为变量赋值 因此,您对不存在的属性的使用(您定义倍数!)typeOfMenu将被完全忽略。

你需要了解的是什么是错别字:
这是一个配置标记 您所要做的就是填充一个复杂的PHP数组,该数组配置页面/页面部分的呈现。

为简化起见,您可以选择将值存储在寄存器中,以便在以后的渲染过程中使用。因此,您可以避免多次计算值。但是你不能改变一个命名的寄存器。

此外,您不能在typoscript条件中使用寄存器,因为在评估任何typoscript之前评估条件 - 并且可以设置寄存器。

您可以使用.stdWrap.if条件中的寄存器值。

另一方面,您可以定义一个寄存器并根据stdWrap.if条件确定值。

如果使用流体模板而不是typoscipt构建菜单,则可以在PHP中使用viewhelper,这可能对您更熟悉。

编辑:

所以让我们试着建立一个例子:

#start with pages that have subpages:
IFSUB = 1
IFSUB {
    // as we need to to the linking later no default linking:
    doNotLinkIt = 1
    # let's define registers
    stdWrap.innerWrap.cObject = LOAD_REGISTER
    stdWrap.innerWrap.cObject {
        # define register 'typeOfMenu'
        typeOfMenu.cObject = TEXT
        typeOfMenu.cObject {
            # set value 1
            value = 1
            # override with 0
            override = 0
            # override only if this CONTENT is empty
            override.ifEmpty.cObject = CONTENT
            override.ifEmpty.cObject {
                # select all CEs, from this page in column 99
                table = tt_content
                select {
                    pidInList.field = uid
                    where = colPos=99  and deleted=0 and hidden=0
                }
                # render only the uid, so even an empty CE will trigger  
                renderObj = TEXT
                renderObj.field = uid
            } 
        }
    }
    # now we link
    stdWrap.typolink{              
        parameter.field =  uid
        ATagParams = class="vertical menu -- {register:typeOfMenu} --"
        ATagParams {
            insertData = 1
            # override the std value: 
            override = class="dropdown shrink" data-toggle="sous-menu{register:count_MENUOBJ}"
            override {
                insertData = 1
                # override only if register typeOfMenu is 1
                stdWrap.if.equals = 1
                stdWrap.if.data = register:typeOfMenu
            }
        }
    }
}

(从内存构建,没有测试。我希望它有效)

答案 2 :(得分:0)

解决方案是:

        IFSUB = 1
    IFSUB {
        // as we need to to the linking later no default linking:
        doNotLinkIt = 1

        # let's define registers
        stdWrap.innerWrap.cObject = LOAD_REGISTER
        stdWrap.innerWrap.cObject {
            # define register 'typeOfMenu'
            typeOfMenu.cObject = TEXT
            typeOfMenu.cObject {
                # set value 1
                value = 1
                # override with 0
                override = 0
                # override only if this CONTENT is empty
                override.ifEmpty.cObject = CONTENT
                override.ifEmpty.cObject {
                    # select all CEs, from this page in column 99
                    table = tt_content
                    select {
                        pidInList.field = uid
                        where = colPos=99  and deleted=0 and hidden=0
                    }
                    # render only the uid, so even an empty CE will trigger  
                    renderObj = TEXT
                    renderObj.field = uid
                }
            }
        }
        # now we link
        stdWrap.typolink {              
            parameter.field =  uid
            ATagParams = class="dropdown shrink" data-toggle="sous-menu{register:count_MENUOBJ}"
            ATagParams {
                insertData = 1
                # override the std value: 
                #override = class="vertical menu -- {register:typeOfMenu} --"
                override = class="vertical menu"
                override {
                    #insertData = 1
                    # override only if register typeOfMenu is 1
                    if.value = 1
                    if.equals.dataWrap = {register:typeOfMenu}
                }
            }
        } ...

感谢BerndWilkeπφ! 最好的问候