0
votes

I need to change the appearance of a menu following the presence or absence of content in tt_content. For that, I did this but it does not work, I have errors on the test:

      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]            
        ...
  • ERROR: Line 2244: Object Name String, "[globalVar" contains invalid character "[". Must be alphanumeric or one of: "_:-."

Does anyone have an idea? Best regards !


it's almost that, but it does not work (Bernd Wilke solution ...). I do not understand the sql query well. And there is an offset, it is the first typeOfMenu is written for the second. In fact I would like this:

<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> .....

And, when there is something in colPos=99, I would like to have:

     <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>

Here the typoscript part that I had very difficult to code and that works, without taking into account 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

Best regards

Now if I do this :

# 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

I get some values (reversed, it's not quite that yet) for 'typeOfMenu' corresponding to colPos = 99, it's almost good, but what is lower in the script is not taken into account.

If I do this :

# 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
                }
            }
        }

I get this :

<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

...

When it is 'typeOfMenu' = 1 it is that I have no droppane but there is no change of : override = class="dropdown shrink" data-toggle="sous-

3
what version of TYPO3 do you use?Bernd Wilke πφ
typo3-9.2.0, i am looking for a part of your script, can i mail you all my menu by mail ?B. Guegan

3 Answers

0
votes

You can't use those TypoScript conditions within a block of { }.

e.g. this is not allowed:

lib.test {
    foo = bar

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

Instead do it like this:

lib.test {
    foo = bar
}

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

Typoscript is no programming language where you can assign values to variables.
So your usage of the not existing properties (you define multiples!) typeOfMenu is ignored completely.

You need to understand what typoscript is:
It is a configuration markup.
All you do is fill a complex PHP array which configures the rendering of the page / or parts of the page.

For some simplification you have the option to store a value in registers which can be used on later rendering processes. So you can avoid to calculate a value multiple times. But you can't change a named register.

Furthermore you cant use registers in typoscript conditions, as conditions are evaluated before any typoscript gets evaluated - and could set a register.

What you can do is using a register value inside of .stdWrap.if conditions.

On the other hand you can define a register and decide the value depending on stdWrap.if conditions.

If you build your menus with fluid templates instead of typoscipt you can use viewhelpers in PHP, which might be more familiar to you.


EDIT:

so let's try to build an example:

#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
            }
        }
    }
}

(build from memory, without tests. I hope it works)

0
votes

The solution is:

        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}
                }
            }
        } ...

Thanks to Bernd Wilke πφ ! Best regards