Welcome to Geeklog Friday, September 25 2020 @ 10:55 pm EDT

Geeklog Forums

Defining a template for a new plugin


Status: offline

Al262

Forum User
Junior
Registered: 19/10/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.
PHP 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>
 
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 14/01/05
Posts: 1569
Location:la rochelle, France
Hi,

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

sample.thtml

PHP 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

PHP 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
 Quote

Status: offline

Al262

Forum User
Junior
Registered: 19/10/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?
 Quote

Status: offline

::Ben

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

PHP Formatted Code

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

with

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

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

Status: offline

Al262

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

Thank you
al
 Quote

All times are EDT. The time is now 10:55 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content