nested template not working

A general technical discussion area for patTemplate.
progster
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 213
Joined: Thu Aug 18, 2005 7:34 pm
Location: Belgium
Contact:

nested template not working

Postby progster » Wed Jun 14, 2006 3:43 pm

Hi there,

we're trying to move joomlaboards templating engine to patTemplate, but I've ran into a problem. I'm using an oddEven type template for alternating rows. So far everything works, now within each sub (_odd and _even) I'd like to check for another variable and this just doesn't work for some reason. Anybody care to enlighten me? The code is included below:

forum_flatview.xml

Code: Select all

<patTemplate:tmpl name="jb-forum-flatview">
   <table border="0" cellspacing="1" cellpadding="3" width="100%" class="contentpane" style="text-align: left;">
   <tr>
   
      <td class="sectiontableheader" width="5%"> </td>
       <td class="sectiontableheader" width="5%" align="center"> </td>
      <td class="sectiontableheader" width="5%" align="center"> </td>
      <td class="sectiontableheader" width="30%"align="center"><strong>{GEN_TOPICS}</strong></td>
      <td class="sectiontableheader" width="5%" align="center"><strong>{GEN_REPLIES}</strong></td>
      <td class="sectiontableheader" width="5%" align="center"><strong>{GEN_HITS}</strong></td>
      <td class="sectiontableheader" width="20%" align="center"><strong>{GEN_AUTHOR}</strong></td>
      <td class="sectiontableheader" width="25%" align="center" colspan="2"><strong>{GEN_LAST_POST}</strong></td>
   </tr>
   <patTemplate:tmpl name="jb-forum-flatview-row" type="oddeven">
      <patTemplate:sub condition="__odd">
         <tr class="sectiontableentry1">
            <patTemplate:tmpl type="condition" conditionvar="jb-forum-flatview-row.newposts">
                   <patTemplate:sub condition="1">
                  <td width="5%">{UNREAD}</td>
                   </patTemplate:sub>
               <patTemplate:sub condition="0">
                  <td width="5%">{READ}</td>   
               </patTemplate:sub>
            </patTemplate:tmpl>
            <td width="4%"  align="center">{TOPICTYPE}</td>
            <td width="4%"  align="center"><img src="{TOPICEMOTICON}" alt="topic emoticon" /></td>
            <td width="30%" align="center">{SUBJECT}</td>
            <td width="5%"  align="center">{REPLIES}</td>
            <td width="5%"  align="center">{HITS}</td>
            <td width="20%"  align="center">{AUTHOR}</td>
            <td width="25%"  align="center">
               <small>{LASTPOSTTIME}</small><br />
               <small>{GEN_BY} {LASTPOSTAUTHOR}</small>
            </td>
            <td width="2%" align="center"><a href="{LASTPOSTURL}">{LASTPOSTIMG}</a></td>
         </tr>
      </patTemplate:sub>
      <patTemplate:sub condition="__even">
         <tr class="sectiontableentry2">
                  <patTemplate:tmpl type="condition" conditionvar="jb-forum-flatview-row.newposts">
                   <patTemplate:sub condition="1">
                  <td width="5%">{UNREAD}</td>
                   </patTemplate:sub>
               <patTemplate:sub condition="__default">
                  <td width="5%">{READ}</td>   
               </patTemplate:sub>
            </patTemplate:tmpl>
            <td width="4%"  align="center">{TOPICTYPE}</td>
            <td width="4%"  align="center"><img src="{TOPICEMOTICON}" alt="topic emoticon" /></td>
            <td width="30%" align="center">{SUBJECT}</td>
            <td width="5%"  align="center">{REPLIES}</td>
            <td width="5%"  align="center">{HITS}</td>
            <td width="20%"  align="center">{AUTHOR}</td>
            <td width="25%"  align="center">
               <small>{LASTPOSTTIME}</small><br />
               <small>{GEN_BY} {LASTPOSTAUTHOR}</small>
            </td>
            <td width="2%" align="center"><a href="{LASTPOSTURL}">{LASTPOSTIMG}</a></td>
         </tr>
      </patTemplate:sub>
   </patTemplate:tmpl>
   </table>
</patTemplate:tmpl>


Code feeding the template:

Code: Select all

$arr_jb_rows=array();
$int_jb_counter=0;
foreach ($arr_jb_messages as $obj_jb_message) {
   $arr_jb_rows[$int_jb_counter]['topictype']=jb_get_topic_type($obj_jb_message);
   $arr_jb_rows[$int_jb_counter]['topicemoticon']=$topic_emoticons[$obj_jb_message->topic_emoticon];
   $arr_jb_rows[$int_jb_counter]['newposts']=0;
   if ($obj_jb_message->locked!=1) {
      if ($sbConfig['showNew'] && $my->id !=0 && ! $obj_jb_message->moved)
         if (($prevCheck<$obj_jb_message->lastpost && (!in_array($obj_jb_message->id, $read_topics) || $read_topics[$obj_jb_message->id]<$obj_jb_message->lastpost)))
            $arr_jb_rows[$int_jb_counter]['newposts']=1;      
      if ($sbConfig["allowemail"]==1)
         $arr_jb_rows[$int_jb_counter]['author']='<a href="mailto:'. $obj_jb_message->email . '" >'.      
      $obj_jb_message->name.'</a>';
      else
         $arr_jb_rows[$int_jb_counter]['author']=$obj_jb_message->name;            
      $arr_jb_rows[$int_jb_counter]['hits']=$obj_jb_message->hits;
      $arr_jb_rows[$int_jb_counter]['replies']=$obj_jb_message->replies;
      $arr_jb_rows[$int_jb_counter]['lastposttime']=$last_reply[$obj_jb_message->id]->time;
      $arr_jb_rows[$int_jb_counter]["lastpostauthor"]=$last_reply[$obj_jb_message->id]->name;
      $arr_jb_rows[$int_jb_counter]["lastposturl"]=sefRelToAbs($sbs2.'&func=view&catid='.$catid.'&getlast=1&id='.$last_reply[$obj_jb_message->id]->id).'#'.$last_reply[$obj_jb_message->id]->id;
      $arr_jb_rows[$int_jb_counter]["subject"]='<a href="'.sefRelToAbs($sbs2.'&func=view&id='.$obj_jb_message->id.'&catid='.$catid).'">'.$obj_jb_message->subject.'</a>';
      if ($obj_jb_message->replies+1 > $sbConfig['messages_per_page'])
         $arr_jb_rows[$int_jb_counter]["subject"].='<br />'.jb_generate_pagelist($obj_jb_message);
   }
   else {
      $newURL='';
      $database->setQuery("SELECT `message` FROM #__sb_messages_text WHERE `mesid`='".$obj_jb_message->id."'");
      $newURL=$database->loadResult();
      $arr_jb_rows[$int_jb_counter]["subject"]='<a href="'.sefRelToAbs($sbs2.'&func=view&'.$newURL).'">'.   
                                 $obj_jb_message->subject.'</a>';
   }
   $int_jb_counter++;
}   
$jb_unread=$sbIcons['unreadmessage'] ? '<img src="'.$mls.'/modules/mod_sbicons/'.$sbIcons['unreadmessage'].'" border="0" alt="'._GEN_UNREAD.'" title="'._GEN_UNREAD.'"/>' : '<span class="sb_new">'.$sbConfig['newChar'].'</span>';
   $jb_read=$sbIcons['readmessage'] ? '<img src="'.$mls.'/modules/mod_sbicons/'.$sbIcons['readmessage'].'" border="0" alt="'._GEN_NOUNREAD.'" title="'._GEN_NOUNREAD.'"/>' : '<span class="sb_notnew">'.$sbConfig['newChar'].'</span>';
   $str_lastreply=$sbConfig['latestpost'] ? '<img src="'.$mls.'/modules/mod_sbicons/'.$sbIcons['latestpost'].'" border="0" alt="'._SHOW_LAST.'" />' : '  <img src="'.$sbs.'/emoticons/icon_newest_reply.gif" border="0"  width="18" height="9" alt="'._SHOW_LAST.'" title="'._SHOW_LAST.'" />';
   $obj_jb_tmpl->readTemplatesFromFile( "forum_flatview.html" );
   $obj_jb_tmpl->addVar('jb-forum-flatview','GEN_TOPICS',_GEN_TOPICS);
   $obj_jb_tmpl->addVar('jb-forum-flatview','GEN_REPLIES',_GEN_REPLIES);
   $obj_jb_tmpl->addVar('jb-forum-flatview','GEN_HITS',_GEN_HITS);
   $obj_jb_tmpl->addVar('jb-forum-flatview','GEN_AUTHOR',_GEN_AUTHOR);
   $obj_jb_tmpl->addVar('jb-forum-flatview','GEN_LAST_POST',_GEN_LAST_POST);
   $obj_jb_tmpl->addVar('jb-forum-flatview-row','GEN_BY',_GEN_BY);   
   $obj_jb_tmpl->addVar('jb-forum-flatview-row','READ',$jb_read);
   $obj_jb_tmpl->addVar('jb-forum-flatview-row','UNREAD',$jb_unread);
   $obj_jb_tmpl->addVar('jb-forum-flatview-row','LASTPOSTIMG',$str_lastreply);
   $obj_jb_tmpl->addRows( "jb-forum-flatview-row",$arr_jb_rows);
   $obj_jb_tmpl->displayParsedTemplate('jb-forum-flatview');


Ps: don't mind the ugly code, lot of legacy in there  :(
Last edited by progster on Fri Jan 12, 2007 3:46 pm, edited 1 time in total.

Narcissus
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 109
Joined: Wed Sep 07, 2005 5:02 pm

Re: nested template not working

Postby Narcissus » Tue Jun 20, 2006 6:43 am

Although I haven't really looked at your code, here's something that I found necessary sometimes: if trying to access 'subtemplates' in a fom, I found that I needed to explicitly call the loadTemplate on the parent template.

Anyway, try calling something like:
$tmpl->loadTemplate('body');

in your code. Generally, that one line (after loading the HTML file by setting the 'src' attribute) has always fixed my subtemplating issues. However, you might need to replace 'body' with the name of your 'parent' template...

Just a thought, anyway.

User avatar
dknight
Joomla! Guru
Joomla! Guru
Posts: 708
Joined: Thu Aug 18, 2005 5:14 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: nested template not working

Postby dknight » Wed Jun 21, 2006 4:10 am

In my experience, you need to explicitly pass the variable to the subtemplate, ie

[php]
$obj_jb_tmpl->addVar('jb-form-newpost','newposts',$newpost_conditionvar_value_here);
[/php]

Code: Select all

      <patTemplate:tmpl name="jb-forum-newpost" type="condition" conditionvar="newposts">
         <patTemplate:sub condition="1">
            <td width="5%">{UNREAD}</td>
         </patTemplate:sub>
         <patTemplate:sub condition="0">
            <td width="5%">{READ}</td>
         </patTemplate:sub>
      </patTemplate:tmpl>
Lee - Mosets Consulting
Developer of Real Estate and Directory component for Joomla!
Website: www.mosets.com

progster
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 213
Joined: Thu Aug 18, 2005 7:34 pm
Location: Belgium
Contact:

Re: nested template not working

Postby progster » Sun Jun 25, 2006 4:14 pm

yeah, but the value is different for each row... how would I go about doing that?

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

Re: nested template not working

Postby Alejo » Thu Jul 06, 2006 6:02 pm

progster wrote:yeah, but the value is different for each row... how would I go about doing that?


Try using the varscope attribute in the subtemplate, like this:

Code: Select all

<patTemplate:tmpl type="condition" conditionvar="jb-forum-flatview-row.newposts" varscope="jb-forum-flatview-row">


This way you can still address the parent row template and all variables are available to the subtemplate. Does it work?

progster
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 213
Joined: Thu Aug 18, 2005 7:34 pm
Location: Belgium
Contact:

Re: nested template not working

Postby progster » Sat Jul 08, 2006 2:10 pm

Alejo: I'll try that, thanks!

User avatar
pollen8
Joomla! Explorer
Joomla! Explorer
Posts: 350
Joined: Wed Aug 17, 2005 10:32 pm
Location: la Rochelle - France
Contact:

Re: nested template not working

Postby pollen8 » Mon Jul 10, 2006 3:57 pm

also check out the predefined pattemplate variables, theres one for odd/even which will allow you to cut out duplicating the html for odd/even rows:

Code: Select all

<tr class="oddrow{PAT_IS_EVEN}">
aka

progster
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 213
Joined: Thu Aug 18, 2005 7:34 pm
Location: Belgium
Contact:

Re: nested template not working

Postby progster » Sat Aug 19, 2006 12:51 am

a bit late, but as others may be interested, the solution suggested above works!


Return to “patTemplate”

Who is online

Users browsing this forum: No registered users and 1 guest