1
Daigoro
Smarty templates in admin... Possible?
  • 2004/3/13 16:14

  • Daigoro

  • Quite a regular

  • Posts: 223

  • Since: 2003/7/3 2


Basically the topic says it all.

I'd like to use smarty to build the admin interface for a module I'm working at, but is it possible, and if it is, can somebody please provide an example.

Thanks in advance.
--
Daigoro

2
fatman
Re: Smarty templates in admin... Possible?
  • 2004/3/13 16:39

  • fatman

  • Friend of XOOPS

  • Posts: 176

  • Since: 2003/12/13


I don't believe this is possible. I have tried a few times to hack in smarty, but in the end gave up. If you really want to use smarty for an admin page, you can build a module page and manually control access with php but you loose the integration with the groups section of the back end.

I found this over at the dev.xoops wiki. Admin themeing How To, but I'm not sure it is relevant to the current release or the next release of xoops.

edit: I see in the dev.xoops wiki that the above link is classified as a core function in development. This is an interesting approach for the admin side.

I have to wonder why Smarty hasn't been adopted as the standard for all XOOPS interfaces. Admin or not. There must be a reason. I'm not sure what that is however.

3
Daigoro
Re: Smarty templates in admin... Possible?
  • 2004/3/13 17:04

  • Daigoro

  • Quite a regular

  • Posts: 223

  • Since: 2003/7/3 2


I see.

I, too, wonder why the integration of smarty hasn't been executed all the way. It seems stupid to have two methods for making the same work, and Smarty realy is smart and easy to work with.

Regards.

4
skalpa
Re: Smarty templates in admin... Possible?
  • 2004/3/13 20:19

  • skalpa

  • Quite a regular

  • Posts: 300

  • Since: 2003/4/16


Quote:
edit: I see in the dev.xoops wiki that the above link is classified as a core function in development. This is an interesting approach for the admin side.


I'll remove this article. This has never been sent to CVS coz I realised it was way too complicated, and it will be implemented differently.

However, you can use Smarty in the admin side already.

The admin interface is generated like this:
- The header is sent during xoops_cp_header()
- The current module generates the content of the page
- The footer is sent with xoops_cp_footer()

The fact that the xoops_cp_xxxx() functions use PHP and not smarty doesn't prevent you from using it to generate the content part: you just have to manually instanciate the engine and call display()

(Note: I can't check this right now, so I hope my memory is good enough ).
xoops_cp_header();
if ( !isset(
$xoopsTpl) ) { // Just in case, for new releases
    
$xoopsTpl = new XoopsTpl();
}
$xoopsTpl->assign'goan''smee' );
$xoopsTpl->display'db:mypagetemplate.html' );
xoops_cp_footer();


Skalpa.>

5
fatman
Re: Smarty templates in admin... Possible?
  • 2004/3/13 20:48

  • fatman

  • Friend of XOOPS

  • Posts: 176

  • Since: 2003/12/13


NICE ! Thanks skalpa

I'm bookmarking this thread !

6
Daigoro
Re: Smarty templates in admin... Possible?
  • 2004/3/13 21:56

  • Daigoro

  • Quite a regular

  • Posts: 223

  • Since: 2003/7/3 2


Thanks Skalpa,

I didn't try it out yet, but it looks very much like something I allready tried - however, I forgot the
$xoopsTpl = new XoopsTpl();
and failed.
This I'm sure will work!

Now I'm just wondering where I can get a memory-upgrade to equal yours!

7
Daigoro
Re: Smarty templates in admin... Possible?
  • 2004/3/13 23:03

  • Daigoro

  • Quite a regular

  • Posts: 223

  • Since: 2003/7/3 2


Now I've implemented my first smarty template driven admin section.
I had to add a few lines of code.

Here's what I did.

In the admin page I added the following lines (Bold text is the original code, or test code!):
[b]global $xoopsModule;[/b]
 [
b]xoops_cp_header();[/b]
 require_once 
XOOPS_ROOT_PATH.'/class/template.php';
 if ( !isset(
$xoopsTpl) ) { // Just in case, for new releases    
  
$xoopsTpl = new XoopsTpl();
  
$oldsystem true;
 }else 
$oldsystem false;

 
$xoopsOption['template_main'] = 'ad_skel_testmenu.html'// To be compatible with existing system.
[b]// your code starts:[/b]
 
[b]$xoopsTpl->assign'ModuleUrlPath'XOOPS_URL."/modules/".$xoopsModule->getVar('dirname'));[/b]
 [
b]$xoopsTpl->assign'ModuleRootPath'XOOPS_ROOT_PATH."/modules/".$xoopsModule->getVar('dirname'));[/b]
 [
b]$xoopsTpl->assign'goan''smee' );[/b]
[
b]// Your code ends.[/b]

 
if ($oldsystem) { // Don't execute if newer versions has smarty implemented.
  
if (isset($xoopsOption['template_main'])) {
   
$xoopsTpl->xoops_setCaching(0);
   
$xoopsTpl->display('db:'.$xoopsOption['template_main']);
  }
 }
 [
b]xoops_cp_footer();[/b]



To go with this code, I made a template file called ad_skel_testmenu.html' containing:
<p>
 <
center>
  <
b>Admin smarty test!</b><br />
 </
center>
 
Path is: <{$ModuleRootPath}><br />
 
Url is: <{$ModuleUrlPath}><br />
</
p>


and finaly I added the following lines to the xoops_version.php file:
$modversion['templates'][1]['file'] = 'ad_skel_testmenu.html';
$modversion['templates'][1]['description'] = 'Test of smarty in admin..';


Thanks for your help everyone!

Idear:
It might be a good thing to place all admin templates in a directory called admin under templates, just like blocks.
We might aswell try to make a standard, so that smarty can be propperly implemented in the system, and modules will continue to function.

8
skalpa
Re: Smarty templates in admin... Possible?
  • 2004/3/15 0:14

  • skalpa

  • Quite a regular

  • Posts: 300

  • Since: 2003/4/16


Quote:
It might be a good thing to place all admin templates in a directory called admin under templates, just like blocks.


Actually you can already do this also (not extensively tested, but I've already done it):
- create "admin" folder within templates
- $modversion['templates'][1]['file'] = 'admin/ad_skel_testmenu.html';
- display('db:admin/ad_skel_testmenu.html')


skalpa.>

9
Daigoro
Re: Smarty templates in admin... Possible?
  • 2004/3/18 18:31

  • Daigoro

  • Quite a regular

  • Posts: 223

  • Since: 2003/7/3 2


Thanks Skalpa.

I allready knew it was possible, but I thought it would be good to make a public XOOPS rule, rather then just something thats possible. Thats what I tried to write!

Regards.

10
fatman
Re: Smarty templates in admin... Possible?
  • 2004/4/8 3:40

  • fatman

  • Friend of XOOPS

  • Posts: 176

  • Since: 2003/12/13


I finally got around to trying this little hack out. Works very well.

Login

Who's Online

125 user(s) are online (57 user(s) are browsing Support Forums)


Members: 0


Guests: 125


more...

Donat-O-Meter

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

Latest GitHub Commits