Re: Blocklayout/xarpages & dynamic data
"Jason" <[email protected]>
| Newsgroups | gmane.comp.cms.xaraya.user |
|---|---|
| Organization | Xaraya |
| Message-ID | <[email protected]> |
"Christopher Torgalson" <[email protected]> wrote in message news:mailman.233.1165859295.6153.xaraya_user-gn8pmO+6nsymdvSpIQae8A@public.gmane.org > Hello, > > On 12/11/06, Brian Bain <[email protected]> wrote: >> >> >> Christopher Torgalson wrote: >> > Hello list, >> > >> > After lurking on the list for a couple of years, I'm finally trying to >> > build a Xaraya site. At the moment, I'm trying to add an id attribute >> > into the rendering of xarpages' default menu block. The id attribute >> > will come from a dynamic data field I added to one of xarpages page >> > types. The problem is that in the menu block I'm having trouble >> > accessing the value of the dynamic data field, but I can't tell if >> > it's a) a problem with my understanding of blocklayout, b) a problem >> > with my understanding of xarpages, or c) [unlikely I think...] a bug. >> > >> > For example, I can use the following snippet in the template: >> > >> > <ul> >> > <xar:loop name="$page.dd"> >> > <li>#$loop:key# => #$loop:item#</li> >> > </xar:loop> >> > </ul> >> > >> > I assume it's not a problem with variable scope or similar because >> > this works, and yields output something like this (as expected): >> > >> > <ul> >> > <li>page_title => Lorem Ipsum</li> >> > <li>page_id => fubar</li> >> > <li>page_content => Dolor sit amet consectetuer. Lipsum.</li> >> > </ul> >> > >> > The problem arises when I try to access just /one/ of the dd fields >> > like this: >> > >> > <ul> >> > <xar:loop name="$page.dd"> >> > <li>#$loop:item['page_id']#</li> >> > </xar:loop> >> > </ul> >> > >> > ...or like this: >> > >> > <ul> >> > <xar:loop name="$page.dd"> >> > <li>#$loop:item.page_id#</li> >> > </xar:loop> >> > </ul> >> > >> > If I read the blocklayout RFC document correctly, either snippet >> > should work, but what happens instead is that instead of the contents >> > of ONE field, I get the FIRST CHARACTER of EACH field, something like >> > this (assuming the same set of fields as shown in the output above): >> > >> > <ul> >> > <li>L</li> >> > <li>f</li> >> > <li>D</li> >> > </ul> >> > >> > I have no idea what backasswards thing I may have done or what >> > blocklayout/xarpages subtlety I've overlooked, but it sure /looks/ >> > like I've set things up correctly. If anyone has any comments advice, >> > suggestions or even educational personal abuse, I'd be happy to listen >> > to it... >> > >> > >> > Thanks, >> > >> > -- CT >> > _______________________________________________ >> > Xaraya_user mailing list >> > [email protected] >> > http://xaraya.com/mailman/listinfo/xaraya_user >> > >> > >> Hi CT, >> I'm not sure I can help with your exact issue, but I wanted to raise a >> question to everyone else about the loop tag. I recall when I first >> started working with Xaraya it was the recommended way of doing loops, >> however, I've since found the foreach syntax to be much easier. >> >> Does anyone still recommend the loop tag, and what are its benefits? I >> seem to remember it adding a lot of compexity to my templates. >> >> The above example would be more like this using foreach (if I'm right in >> assuming the array looks something like $page['dd'][0]['page_id'] => >> "Loren Ipsum"). >> >> <ul> >> <xar:foreach in="$page['dd']" value="$item"> >> <li>#$item['page_id']#</li> >> </xar:foreach> >> </ul> > > > You may be right Brian--I used 'loop' because according to the > blocklayout rfc "The elements are guaranteed to be processed in the > same order as they are stored in this array.". > > I should add, for the sake of completeness, that I tried the foreach > loop as well--loop was just the final iteration before I decided I > didn't know what I was doing wrong... I use <xar:loop> too, because is it so easy to use. The following, in a xarpages menu block, should list the names of all the xarpages in the current hierarchy: <xar:loop name="pages"> #$loop:item.name#, </xar:loop>