Loops in patTemplate

A general technical discussion area for patTemplate.
Locked
User avatar
romina
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Sat May 05, 2007 5:59 am
Location: Rosario, Argentina

Loops in patTemplate

Post by romina » Sat May 19, 2007 8:57 pm

Hi...  :-[ nobody seems to have posted since my last post!

I was able to make conditionals work  :laugh:

However now I'm having problems making loops work! I have tried different solutions that I have found on this forum but none worked. Perhaps doing something wrong, but I can't seem to figure out what exactly that is.

My php code returns the following loop:

Title (1)
    Subtitle (1)
        Something1
        Something2
        ...
    Subtitle (2)
        Something3
        ...
    ...
Title (2)
    etc.

I created a template, that after reading some urls said that it would automatically loop, using the following code

Code: Select all

Template:
<mos:tmpl name="rows">
	<u>{items_Title}</u>
</mos:tmpl>

php template call:
// returns 2 $row
foreach ($rows as $row) {
          $title = $row->title;
          $tmpl->addObject( 'rows', $rows, 'items_');
}
But that just prints

Code: Select all

{items_Title}  {items_Title}
When it should print

Code: Select all

Title1 Title2
Any ideas? Thank you in advance for all your help. I'm quite frustrated... been working with this really simple loop for hours :(

User avatar
masterchief
Joomla! Hero
Joomla! Hero
Posts: 2247
Joined: Fri Aug 12, 2005 2:45 am
Location: Brisbane, Australia
Contact:

Re: Loops in patTemplate

Post by masterchief » Sat May 19, 2007 10:16 pm

One level deep is doable (your Subtitles).  Two levels deep (your Somethings) is insanely difficult.  I've reverted back to back to the php way of doing it for this very reason.  I love the pat syntax but the difficulties of loops was getting too restrictive for me.
Andrew Eddie - Tweet @AndrewEddie
<><
http://eddify.me
http://www.kiva.org/team/joomla - Got Joomla for free? Pay it forward and help fight poverty.

User avatar
romina
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Sat May 05, 2007 5:59 am
Location: Rosario, Argentina

Re: Loops in patTemplate

Post by romina » Sat May 19, 2007 10:21 pm

Gosh :(

Terrible news!

This question may sound silly but... what do you mean with 'the php way of doing it'? Do you think I should embed html in the php?  :'(

User avatar
masterchief
Joomla! Hero
Joomla! Hero
Posts: 2247
Joined: Fri Aug 12, 2005 2:45 am
Location: Brisbane, Australia
Contact:

Re: Loops in patTemplate

Post by masterchief » Sun May 20, 2007 3:26 am

Yeah, I tried and tried, but some sites just got too hard.  Don't get me wrong it's a good system, but it has brick walls.

Ok, the php way is just that, using php template files.  Have a look at the 1.5 Beta in, say, one of the weblinks views.  We are using php layouts now in a similar way to what Savant does.
Andrew Eddie - Tweet @AndrewEddie
<><
http://eddify.me
http://www.kiva.org/team/joomla - Got Joomla for free? Pay it forward and help fight poverty.

Alejo
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 220
Joined: Fri Aug 19, 2005 12:28 pm
Contact:

Re: Loops in patTemplate

Post by Alejo » Sun May 27, 2007 1:52 pm

romina wrote: I created a template, that after reading some urls said that it would automatically loop, using the following code

Code: Select all

Template:
<mos:tmpl name="rows">
	<u>{items_Title}</u>
</mos:tmpl>

php template call:
// returns 2 $row
foreach ($rows as $row) {
          $title = $row->title;
          $tmpl->addObject( 'rows', $rows, 'items_');
}
But that just prints

Code: Select all

{items_Title}  {items_Title}
When it should print

Code: Select all

Title1 Title2
Any ideas? Thank you in advance for all your help. I'm quite frustrated... been working with this really simple loop for hours :(
If $rows contains all your rows then try the php code without the foreach statement:

Code: Select all

        $tmpl->addObject( 'rows', $rows, 'items_');
If you need to loop through the $rows, then try this:

Code: Select all

foreach ($rows as $row) {
          $title = $row->title;
          $tmpl->addObject( 'rows', $row, 'items_');
          $tmpl->parseTemplate('rows','a');
}
https://www.jreviews.com/joomla directory, classifieds, and reviews system for Joomla and WordPress


Locked

Return to “patTemplate”