Topic: Xanthia / Smarty and Templates...
omorel

Noob
Noob
Posts: 8

Posted:
Apr 20, 2004

Hi,

I'm developping a new module for pn and I am using the new Xanthia module for pn version 0.726-1.

I would like to do this :

-> main fonction :
-> fonction "a" :
-> render a template
-> fonction "b" :
-> render another template
-> render a third template.

So how could I append the result of one template to another one ? Oh and I would like to be able to call the templates from inside pn and not from another template...
Chestnut
avatar
Site Admin
Posts: 1320

Posted:
Apr 20, 2004

The Example mod is your best friend ;) (the pncSimpleStatsX also)

I don't fully understand your list with function but I'll go this way... we will be able to correct things.

Code
  1. function yourmod_user_main()
  2. {
  3.  
  4.     // This function renders the main template
  5.    
  6.     //Security
  7.     if (!pnSecAuthAction(0, YOURMOD::', '::', ACCESS_OVERVIEW)) {
  8.         return pnVarPrepHTMLDisplay(_YOURMODNOAUTH);
  9.     }
  10.  
  11.     // New Render Instance
  12.     $pnRender =& new pnRender('YOURMOD');
  13.  
  14.     // Template for main
  15.     return $pnRender->fetch('YOURMOD_user_main.htm');
  16. }
  17.  


Example of applications :
If you want a top menu that will be on all pages, you can do a simple include in your template :

file : yourmod_user_menu.htm
Code
  1. <br />
  2. <br />
  3. <a href="LINK1">LINK1</a> - <a href="LINK2">LINK2</a>
  4. <br />
  5. <br />


Now to include that in your templates :
yourmod_user_main :

Code
  1. <!--&#91;include file="yourmod_user_menu.htm"]-->
  2.  


Voilą for the menu !

Now if you look at function Example_user_view() in the Example mod...
The function fetch all example items :
Code
  1. $items = pnModAPIFunc&#40;'Example',
  2.                           'user',
  3.                           'getall',
  4.                           array&#40;'startnum' => $startnum,
  5.                                 'numitems' => pnModGetVar&#40;'Example',
  6.                                                           'itemsperpage'&#41;));
  7.  

then, (after one or 2 manipulations), input in a template each of these items and all this will be in an array :

Code
  1. $exampleitems = array&#40;);
  2. foreach &#40;$items as $item) {
  3.     $pnRender->assign&#40;$item);
  4.     $exampleitems&#91;] = $pnRender->fetch('example_user_row_read.htm', $item['tid']);
  5. &#125;
  6.  


Now the array var $exampleitems have a template for each item.

Next... the array is sended to another template, the view page :
Code
  1. // ....
  2.     $pnRender->assign&#40;'items', $exampleitems);
  3.     return $pnRender->fetch&#40;'example_user_view.htm');
  4. &#125;
  5.  


In the 'example_user_view.htm', there is a var 'items' that contains a template ('example_user_row_read.htm') for each items.

example_user_view.htm :
Code
  1. <!--&#91;include file="example_user_menu.htm"]-->
  2. <br />
  3. <br />
  4.  
  5. <!--&#91;* Loop through the items and display them   *]-->
  6. <!--&#91;foreach item=item from=$items]-->
  7. <!--&#91;$item]-->
  8. <!--&#91;/foreach]-->
  9.  


This loop and most explicitly, this line :
Code
  1. <!--&#91;$item]-->
  2.  

is our example_user_read.htm template that contains one item of the list. The loop make it so we show all items of the list.

See the example mod and the pncSimpleStats (where I wrote LOTS of crappy comments) for other examples like this.

Hope this helps a bit ! At least for a start !

Chestnut ! Cool
Site Admin
Chestnut
avatar
Site Admin
Posts: 1320

Posted:
Apr 20, 2004

Damn... the pncSimpleStats was made using the pnHTML, not the pnRender. the pncSimpleStatsX is made for the pnRender but I didn't wrote the comments in it...

I must not forget to change that.


Chestnut ! Cool
Site Admin
omorel

Noob
Noob
Posts: 8

Posted:
Apr 20, 2004

Ok, i'll show you what I've done... and maybe you'll be able to help me a bit (no, I'm not too lazy to read what you wrote, I have read it).

so :


it's based on a plugin model. this is a plugin.

Code
  1. function pnsCommentarium_userapi_reviews_short_display&#40;$args)
  2. &#123;
  3.     extract&#40;$args);
  4.  
  5.     if &#40;!pnModAvailable('Reviews')) {
  6.         return ;
  7.     &#125;
  8.  
  9.     $dbconn             = &pnDBGetConn&#40;true);
  10.     $pntable          = &pnDBGetTables&#40;);
  11.    
  12.     $reviews          = &$pntable&#91;'reviews'];
  13.     $reviews_column     = &$pntable&#91;'reviews_column'];
  14.    
  15.     $sql =   "SELECT  $reviews_column&#91;title],
  16.                                    $reviews_column&#91;score],
  17.                             $reviews_column&#91;id]
  18.                  FROM     $reviews
  19.                      WHERE   $reviews_column&#91;reviewer]='" . $uname."'
  20.                  ORDER BY   $reviews_column&#91;id]";
  21.    
  22.     echo $sql;
  23.    
  24.     $results = $dbconn->Execute&#40;$sql);
  25.    
  26.     for &#40;; !$results->EOF; $results->MoveNext()) {
  27.         list&#40;$pn_title, $pn_score, $pn_id) = $results->fields;
  28.         $items&#91;] = array(   'pn_title'            => $pn_title,
  29.                            'pn_score'   => $pn_score,
  30.                            'pn_id'    => $pn_id&#41;;
  31.     &#125;
  32.    
  33.     $pnRender->assign&#40;'items', $items);
  34.     $pnRender->assign&#40;'module', 'Reviews');
  35.    
  36.     return $pnRender->fetch&#40;'pnsCommentarium_reviews_display_short.htm');
  37.  
  38. &#125;
  39.  


this is the main fonction.

Code
  1. function pnsCommentarium_user_main&#40;){
  2.  
  3.     if &#40;!pnSecAuthAction(0, 'pnsCommentarium::', '::', ACCESS_OVERVIEW)) {
  4.         return pnVarPrepHTMLDisplay&#40;_EXAMPLENOAUTH);
  5.     &#125;
  6.  
  7.     $pnRender =& new pnRender&#40;'pnsCommentarium');
  8.  
  9.     $user       = 'omorel';
  10.     $view       = 1;
  11.     $new_window     = 0;
  12.     $target                = 'omorel';
  13.     $modules       = array &#40;0  => array (   'module'   =>     'reviews',
  14.                                             'checked'   => 1&#41;);
  15.            
  16.  
  17.     foreach &#40;$modules as $module) {
  18.        
  19.         $execok = true;
  20.  
  21.         pnModAPILoad&#40;'pnsCommentarium', 'user');
  22.  
  23.         if &#40;$module['checked'] == 1) {        
  24.                
  25.             $result = pnModAPIFunc&#40;  'pnsCommentarium',
  26.                                           'user',   
  27.                                         'fileexist',
  28.                                                                     array&#40;'file' => $module['module']));
  29.            
  30.            
  31.             if &#40;$result == true) {
  32.                 require_once&#40;'modules/pnsCommentarium/plugins/'.pnVarPrepForOs($module['module']).'.php');
  33.             &#125;
  34.             else &#123;
  35.                 $execok = false;
  36.             &#125;
  37.                        
  38.  
  39.             if &#40;$view == 1) {
  40.  
  41.                 if &#40;$execok == true)
  42.                     $moddisplay&#91;] = pnModAPIFunc(   'pnsCommentarium',
  43.                                'user',
  44.                                                              $module&#91;'module'] . '_short_display',
  45.                                                              array&#40;   'uname'        => $target,
  46.                                                      'pnRender' => $pnRender&#41;);
  47.             &#125;
  48.             else &#123;
  49.            
  50.                 if &#40;$execok == true)
  51.                     pnModAPIFunc&#40;      'pnsCommentarium',
  52.                                   'user',
  53.                                         $module&#91;'module'] . '_long_display',
  54.                                         array&#40;  'uname'   => $target));
  55.                                    
  56.             &#125;
  57.         &#125;
  58.     &#125;
  59.  
  60.     return $pnRender->fetch&#40;'pnsCommentarium_reviews_short_display.htm');
  61. &#125;
  62.  


but it only displays pnsCommentarium_reviews_short_display.html ... :(

Please... help me... [/code]
Chestnut
avatar
Site Admin
Posts: 1320

Posted:
Apr 20, 2004

Check the file... I think it would be a better start...

Always remember that the GUI (interface, rendering, the display is in the user functions)...

userapi are function that returns a value like a sql result, etc...

Unless the inevitable I guess.

Note also that the pnModAPILoad is done once... I moved it up.


Chestnut ! Cool
Site Admin
omorel

Noob
Noob
Posts: 8

Posted:
Apr 21, 2004

Ok, there I found my "mistake" or what I misunderstood...

I would like to develop a module which plugins could add their one GUI code... how would it be possible ?

PS : sorry for the silly questions, new to pn...
Chestnut
avatar
Site Admin
Posts: 1320

Posted:
Apr 21, 2004

The file I gave you contains what you ask.

This part :
Code
  1. $items = pnModAPIFunc&#40;'pnsCommentarium',
  2.                            'user',
  3.                            $module&#91;'module'] . '_short_display',
  4.                            array&#40;'uname' => $target));
  5.  


fetches the items (array) you need...
This part :
Code
  1. $pnRender->assign&#40;'item',   $item);
  2. $pnRender->assign&#40;'module', $module['module']); // Not Reviews sorry
  3.  
  4. $moditems&#91;] = $pnRender->fetch('pnsCommentarium_'.$module['module'].'_display_short.htm);
  5.  


Assign the items to the template of the plugin you want :
this : pnsCommentarium_'.$module['module'].'_display_short.htm
Is your display for the plugin.

Chestnut ! Cool
Site Admin