[TYPO3] Getting title of parent item in a menu
Loek Hilgersom
hilgersom at xs4all.nl
Sun Aug 19 17:11:22 CEST 2007
Thanks Joey, it wasn't exactly what I need, but it was a useful trick that is
part of the solution below.
The problem was that I also needed to show only certain subpages, e.g. only
those with downloads, or only those with the wiki. But since those pages all
have the same name I solved this with a condition:
currentpagetitle.cObject = TEXT
currentpagetitle.cObject.data = page:title
temp.custommenu = HMENU
temp.custommenu.wrap = <ul>|</ul>
temp.custommenu {
special = directory
special.value.field = pages
1 = TMENU
1 {
expAll = 1
NO {
doNotShowLink = 1
stdWrap.cObject = LOAD_REGISTER
stdWrap.cObject {
level1Title = TEXT
level1Title.field = title
}
}
}
2 = TMENU
2.NO.allStdWrap {
# Show only if current-page-title and menu-item-title match
if.value < currentpagetitle
if.equals.field = title
# Show title of 1st level page before this item
dataWrap = <li>{register:level1Title}: |</li>
}
}
So a page called 'downloads' is capable of showing a menu with subpages that are
also called 'downloads', and page named 'wiki' can do the same for the
wiki-subpages.
I needed the allStdWrap to be able to hide the unwanted items entirely, but
because of that now only the words downloads/info/wiki are linked, not the
entire line including {register:level1Title}. I tried to achieve that but didn't
succeed. Anyway, it's acceptable like it is now.
Interesting enough I found out that
currentpagetitle.cObject.data = page:title
behaves differently then
currentpagetitle.cObject.field = title
The first one takes the title of the current page (always), the second - when
used in a menu like this one - returns the last title of the last item of that
level.
Thanks,
Loek
JoH asenau wrote:
>> What I'm trying to achieve is this:
>>
>> The page tree looks like this:
>>
>>> --Page1
>>> |--downloads
>>> |--info
>>> \--wiki
>>>
>>> --Page2
>>> |--downloads
>>> |--info
>>> \--wiki
>>>
>> etc.
>>
>> Now I want to show a menu with only pages from the 2nd level but
>> where the link texts also mention the first level:
>>
>> I need links to the subpages, but the titles of those subpages don't
>> say much. Therefore I need to display the title of the level above:
>>
>> <link to info under Page1>Page1:info</link>
>> <link to info under Page2>Page2:info</link>
>> <link to info under Page3>Page3:info</link>
>>
>> Suggestions welcome!
>
> There are two possible ways to do it, depending on something that I can just
> guess:
>
> 1. If you want to show the next level for the current page you can use
> Daniels approach.
> 2. If you want to show the whole menu you could do it like this:
>
> temp.whatever = HMENU
> temp.whatever {
> wrap = <ul>|</ul>
> entryLevel = 0
> 1 = TMENU
> 1 {
> expAll = 1
> NO {
> doNotShowLink = 1
> stdWrap.cObject = LOAD_REGISTER
> stdWrap.cObject {
> level1Title = TEXT
> level1Title.field = title
> }
> }
> }
> 2 = TMENU
> 2 {
> NO {
> allWrap = <li>|</li>
> stdWrap.dataWrap = {register:level1Title}:|title
> }
> }
> }
>
> This will put the title of the level1 page into a register called
> level1Title and then reuse it for the level2 titles. The level1 titles and
> links won't be rendered though. Since level2 will be rendered after each
> corresponding level1 title, the register should change accordingly and
> always contain the correct level1 title.
>
> Not tested, but should be working.
>
> HTH
>
> Joey
>
More information about the TYPO3-english
mailing list