1
kaotik
Xajax+Xoops Smarty Templates
  • 2006/10/19 14:57

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


I'm tring to load a XOOPS smarty template through a xajax function. Has anyone tried this before?
Here's the reason why: Normally you could output standard html code or even a XOOPS form using a xajax function, however the function gets sloppy and hard to understand with the mixture os php and html. Smarty is possible to use inside xajax but I want to use XOOPS own smarty engine so that things such as <{$xoops_url}> get properly interpreted.

Can anyone point me in the right direction on how to call the XOOPS smarty engine to process templates?

Thanks

2
Mithrandir
Re: Xajax+Xoops Smarty Templates

$xoopsTpl->fetch("db:".$name_of_template.");
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

3
tripmon
Re: Xajax+Xoops Smarty Templates
  • 2006/10/19 18:32

  • tripmon

  • Module Developer

  • Posts: 462

  • Since: 2004/2/28


Kaotik,

Mithy showed how to call a dB based template.. Here's more info in case you are trying to create a new smarty template (that is not already in the dB)...


Using Xoops, You assign a smarty template in a PHP page using:
$xoopsOption['template_main'] = 'template_name_here.html';

After you make that decleration you can add values (still in the .php page):
$xoopsTpl->assign('smarty_value'$php_variable);


Now in template_name_here.html, you can use anything you have passed to the template via php (above) as well as native smarty tags
<{if}>
& XOOPS smarty tags:
<{$xoops_url}>


Hope that helps.

4
McNaz
Re: Xajax+Xoops Smarty Templates
  • 2006/10/19 20:56

  • McNaz

  • Just can't stay away

  • Posts: 574

  • Since: 2003/4/21


Quote:
I'm tring to load a XOOPS smarty template through a xajax function. Has anyone tried this before?


Yes. Check out xStreamer at http://xprojects.co.uk.

Cheers.

5
kaotik
Re: Xajax+Xoops Smarty Templates
  • 2006/10/20 12:05

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


Thank you all for your help. However since xajax is only loading a part of my page and not a full page reload I would have to redeclare $xoopsTpl and $xoopsOption for them to work. I've been reading the code of xstreamer to see how McNaz solved this

McNaz: Have you tried the new xajax 0.5?

6
McNaz
Re: Xajax+Xoops Smarty Templates
  • 2006/10/20 12:22

  • McNaz

  • Just can't stay away

  • Posts: 574

  • Since: 2003/4/21


Hey kaotik.

Quote:
Have you tried the new xajax 0.5?


I was _very_ tempted to try it but was rushed at the time of doing xstreamer so had to give it a miss for a few weeks. I do love xAJAX so will definetly look into it in a few weeks.

7
Shiva
Re: Xajax+Xoops Smarty Templates
  • 2006/10/29 17:26

  • Shiva

  • Quite a regular

  • Posts: 280

  • Since: 2006/7/9 1


If someone could provide some basic notes on how to integrate XOOPS module development with Ajax - that would be much appreciated.
Shiva.

8
kaotik
Re: Xajax+Xoops Smarty Templates
  • 2006/10/30 14:39

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


I'll write a tutorial as soon as I get a grasp on the new 0.5 version of xajax.
There were significant changes from 0.2.4 to 0.5. I can say that most are an incredible improvement, while others require rewriting old code.

9
McNaz
Re: Xajax+Xoops Smarty Templates
  • 2006/10/30 17:13

  • McNaz

  • Just can't stay away

  • Posts: 574

  • Since: 2003/4/21


Quote:
There were significant changes from 0.2.4 to 0.5. I can say that most are an incredible improvement,


Oh sweet! I must check out 0.5 as soon as I can catch sometime. .

10
kaotik
Re: Xajax+Xoops Smarty Templates
  • 2006/10/31 12:15

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


Hi McNaz. One great feature of 0.5 is it's new debug mode, which makes it a whole lot easier to understand what's happening with xajax. It also allows customized plugins.

Here's something i figured out today:
When using xajax you have to set your output code to a specified var then use that to be placed in a div (or p or whatever you prefer):
$text "Hello World!";
$objResponse->assign("div1","innerHTML",$text);

In this case $text will be placed inside "div1". My problem was that I couldn't use $xoopsTpl->display because this would start outputing code before xajax started it's process. This is a big NO-NO for xajax and halt's it's execution. Now I could do something like this:
//////////////////////////////////////////
    // set template for xajax response
    
ob_start();
include(
XOOPS_ROOT_PATH.'/modules/kshop/templates/xajax/assignby.php');
    
$text ob_get_contents();
    
ob_end_clean();
        
$objResponse->assign("div1","innerHTML",$text);
///////////////////////////////////////////

Now this would get properly processed and placed into "div1". but the problem is I can NOT use standard smarty code such as <{$xoops_url}> with this method.
Today, while reading Smarty.class.php I finally solved this:
$text $xoopsTpl->fetch('db:admin_smartytest.html'nullnull,FALSE);
$objResponse->assign("div1","innerHTML",$text);

This will now grab the template from DB, process all it's smarty code then place it inside "div1". This is a great method for placing xajax code inside XOOPS blocks.
Since i was so happy solving this problem, I decided to share my solution

Login

Username:
Password:

Lost Password? Register now!

Who's Online

66 user(s) are online (34 user(s) are browsing Support Forums)


Members: 0


Guests: 66


more...

Donat-O-Meter

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

Latest GitHub Commits