Status: offline

Al262

Forum User
Junior
Registered: 10/19/10
Posts: 16
I've looked at the forum and searched thru some of the other plugins thought it might be best to surface a question.

I created a sample.thtml file, but want to understand best practice for setting sample_id and sample_desc as they will repeat based on the number of rows in the sample database table.
Text Formatted Code
       
    <table id="sample" class="tablesorter">
        <thead>
            <tr>
                <th>{lang_sample_id}</th>
                <th>{lang_sample_desc}</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>{sample_id}</td>
                <td>{sample_desc}</td>
            </tr>
        </tbody>
    </table>
 

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Hi,

All the magic of the template class is between <!-- BEGIN mysampleblock --> and <!-- END mysampleblock -->.

sample.thtml

Text Formatted Code

    <table id="sample" class="tablesorter">
        <thead>
            <tr>
                <th>{lang_sample_id}</th>
                <th>{lang_sample_desc}</th>
            </tr>
        </thead>
        <tbody>
            <!-- BEGIN mysampleblock -->
            <tr>
                <td>{sample_id}</td>
                <td>{sample_desc}</td>
            </tr>
            <!-- END mysampleblock -->
        </tbody>
    </table>
 
 


in your php file

Text Formatted Code
$T = new Template($_CONF['path'] . 'plugins/myplugin/templates');
$T->set_file ('mysample','sample.thtml');
$T->set_block('admin', 'mysampleblock','mysamplevariable');

for ( $i=0; $i < $nRows; $i++ ) {
    $row = DB_fetchArray($result);
    $T->set_var(array(
        'sample_id'      =>  $row['sample_id'],
        'sample_desc'    =>  $row['sample_desc']
    ));
     $T->parse('mysamplevariable','mysampleblock',true);
}


Ben
I'm available to customise your themes or plugins for your Geeklog CMS

Status: offline

Al262

Forum User
Junior
Registered: 10/19/10
Posts: 16
I seem to be missing the magic...

After implementing the code, the loop executes for 3 rows, but the display is only the last row.

Thoughts?

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
It is a mistake of inattention. Can you try replacing

Text Formatted Code

$T->set_block('admin', 'mysampleblock','mysamplevariable');

with

Text Formatted Code
$T->set_block('mysample', 'mysampleblock','mysamplevariable');

Ben
I'm available to customise your themes or plugins for your Geeklog CMS

Status: offline

Al262

Forum User
Junior
Registered: 10/19/10
Posts: 16
That did the trick...

Thank you
al