1
phillipd
Smarty templates in an "admin" script are working!
  • 2004/11/4 2:00

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


I finally got Smarty and templates working in an admin script. Here is some sample code, it's sure alot easier to write with smarty!

include '../../../mainfile.php';
include '../../../include/cp_header.php';

$op = "form";

if ( isset($HTTP_POST_VARS['op']) && $HTTP_POST_VARS['op'] == "submit" ) {
$op = "submit";
}

if ( $op == "form" ) {
xoops_cp_header();
require_once SMARTY_DIR.'Smarty.class.php';
$xoopsTpl = new Smarty;
$xoopsOption['template_main'] = 'ecngis_admin.html';
include XOOPS_ROOT_PATH."/header.php";
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";

//
// Just a sample checkbox
//
$tray_locale = new XoopsFormElementTray("");
$locale = new XoopsFormCheckBox("","Locale","0");
$locale->addOption("0","Locale");
$tray_locale->AddElement($locale);
$form = new XoopsThemeForm("", "layerform", "setlayers.php");
$form->addElement($tray_locale);
$form->assign($xoopsTpl);
$xoopsTpl->assign('lang_layers', _MM_LAYERS);

$xoopsTpl->display('db:'.$xoopsOption['template_main']);
xoops_cp_footer();
}

if ( $op == "submit" ) {

Normal coding stuff...

}
?>

2
Dave_L
Re: Smarty templates in an "admin" script are working!
  • 2004/11/29 5:16

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Instead of:

require_once SMARTY_DIR.'Smarty.class.php';
...
$xoopsTpl = new Smarty;


you can do:

require_once XOOPS_ROOT_PATH '/class/template.php';
...
if (!isset(
$xoopsTpl)) {
   
$xoopsTpl = new XoopsTpl();
}


That way, you're using the XOOPS class derived from the Smarty class, so you get the same customizations.

The reason for the "isset" is to (possibly) provide upward compatibility, in case $xoopsTpl gets automatically defined in future versions.

3
Mithrandir
Re: Smarty templates in an "admin" script are working!

Also, do NOT include mainfile.php when you include cp_header.php

XOOPS 2.1 will feature native Smarty (as in just like in a module page) but the tests, I've made so far result in problems if mainfile.php is included before cp_header.php so DON'T DO THAT! please.

Login

Who's Online

300 user(s) are online (184 user(s) are browsing Support Forums)


Members: 0


Guests: 300


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