-->

Load register inside TMENU

2019-08-07 21:02发布

问题:

In a TYPO3 HMENU, the second level TMENU should reproduce the abstract of the first level page.

I do manage to fill the register with a value and use it in the second level TMENU - but I am unable to load the field's content into the register.

So

field = abstract

as well as

value = {field:abstract}
value.insertData = 1

don't produce any output.

How can that register be filled with the parent page's abstract?

Here's the full code.

temp.main_nav = HMENU
temp.main_nav {
  wrap = <nav id="cbp-hrmenu" class="clearfix cbp-hrmenu span12">|</nav>
  entryLevel = 0

  1 = TMENU
  1 {
        noBlur = 1
        expAll = 1
        wrap = <ul class="level1">|</ul>

        NO {

            wrapItemAndSub=<li>|</li>                   

            before.cObject=LOAD_REGISTER
            before.cObject{
                    parentAbstract.stdWrap.cObject=TEXT
                    parentAbstract.stdWrap.cObject{
                        field = abstract
                        #value = {field:abstract}
                        #value.insertData = 1
                    }
            }
        }

    }

  2 < .1
  2.stdWrap.dataWrap = <div class="cbp-hrsub"><div class="cbp-hrsub-inner"><div>{register:parentAbstract}</div><div><ul class="level2">|</ul></div></div><!-- /cbp-hrsub-inner --></div><!-- /cbp-hrsub -->

}

PS: {levelfield} seems to be problematic inside a TMENU, that's why I switched to LOAD_REGISTER

回答1:

Solved it.

The problem was in

2 < .1 

The second TMENU inherited the load_register from the first one and kept filling it. That's why there was a wrong abstract (e.g. an empty one) in it.

Here's the working code:

temp.main_nav = HMENU
temp.main_nav {
  wrap = <nav id="cbp-hrmenu" class="clearfix cbp-hrmenu span12">|</nav>
  entryLevel = 0

  1 = TMENU
  1 {
        noBlur = 1
        expAll = 1
        wrap = <ul class="level1">|</ul>

        NO {

            wrapItemAndSub=<li>|</li>                   

            before.cObject=LOAD_REGISTER
            before.cObject{
                    parentAbstract.cObject=TEXT
                    parentAbstract.cObject{
                        field = abstract
                    }
            }
        }
        // EDIT: if you have additional states, don't forget to add the abstract too
        ACT < .NO
        ACT = 1
        ACT {
         wrapItemAndSub=<li class="dropdown active">|</li>
        }

    }

  2 = TMENU
  2 {
        noBlur = 1
        expAll = 1
        stdWrap.dataWrap = <div class="cbp-hrsub"><div class="cbp-hrsub-inner"><div>{register:parentAbstract}</div><div><ul class="level2">|</ul></div></div><!-- /cbp-hrsub-inner --></div><!-- /cbp-hrsub -->


        NO {
            wrapItemAndSub=<li>|</li>                   
        }

    }

}