1
jeremy
Database not being queried for template
  • 2005/5/9 20:03

  • jeremy

  • Just popping in

  • Posts: 6

  • Since: 2004/3/11


I have a head scratcher of a problem. Hopefully, I'm overlooking something simple that others will see easily.

I am writing a simple module which will just display all the images in a folder and put some text at the top.

Here's the xoopsversion.php:

$modversion['name'] = "Cheeka Peak Plots";//name of module
$modversion['version'] = 1;
$modversion['description'] = "Display the Cheeka Peak Plots";
$modversion['author'] = "Jeremy Smith";
$modversion['credits'] = "";
$modversion['help'] = "";
$modversion['license'] = "GPL see LICENSE";
$modversion['official'] = 0;
$modversion['image'] = "logo.gif";
$modversion['dirname'] = "cpo_plot";//name of directory on server

// Admin things
$modversion['hasAdmin'] = 0;
$modversion['adminpath'] = "";

// Menu/Sub Menu
$modversion['hasMain'] = 1;//make 0 to not have this appear in main menu
$modversion['templates'][1]['file'] = 'plots.html';
$modversion['templates'][1]['description'] = 'Displays all the plots';
?>


Here's the index.php:

include_once '../../mainfile.php';
include_once 
XOOPS_ROOT_PATH.'/header.php';

$dirpath "../../plots/cpo/";
$plots=array();
if (
$xoopsUser) {
   
$dir opendir($dirpath);
   while((
$file readdir($dir)) != false) {
     if (
strlen($file) > && substr(strtolower($file),strlen($file) - 4) === '.png' && !is_dir($file)) {
       
$plots[]=$file;
     }
   }
   
closedir($dir);
}
sort ($plots);
$xoopsTpl->assign('dirpath',$dirpath);
$xoopsTpl->assign('plots',$plots);

include_once 
XOOPS_ROOT_PATH.'/footer.php';
?>


Finally, here's the template:

Hellolook at me!
<{foreach 
from=$plots item=plot}>
<
p>
<
img src="<{$dirpath}><{$plot}>">
p>
<{/foreach}>



When I run this, I just get a blank spot in the page (not an entirely blank page, there's just nothing where the module should be). Turning on the various debug options, I get no php errors, but it's clear that the db isn't being queried for the template. The last two queries are looking for private messages and the system_block_user.html. There's nothing after that.

The variables that I send to $xoopsTpl are making it to smarty fine, but it just has nowhere to put them.

2
ackbarr
Re: Database not being queried for template

in your php code, you need to direct XOOPS to which template should be loaded for the current page:

require('../../mainfile.php');

// We must always set our main template before including the header
[color=008000][b]$xoopsOption['template_main'] = 'plots.html';[/b][/color]

// Include the page header
require(XOOPS_ROOT_PATH.'/header.php');


Also to ensure that your template name doesn't conflict with any others, it is a good practice to prefix your template file with the name of the module:

plots.html would be mymodule_plots.html

3
jeremy
Re: Database not being queried for template
  • 2005/5/9 22:01

  • jeremy

  • Just popping in

  • Posts: 6

  • Since: 2004/3/11


You're awesome. Thanks so much.

Login

Who's Online

308 user(s) are online (271 user(s) are browsing Support Forums)


Members: 0


Guests: 308


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits