1
intel352
smarty is pretty kick*ss
  • 2004/5/6 18:45

  • intel352

  • Module Developer

  • Posts: 824

  • Since: 2003/11/23


i've been playing with XOOPS code steady for a week now (had looked at it in the past, never enough to begin to grasp it)

i'm developing a xoops-based module for my employer, and i wanted to template-ize all html within the module

i started looking at the module templates yesterday to figure out how they work, looked in XOOPS documentation, and today after creating a few simple templates, and then a few hours of struggling, i was able to create a fairly complex (imho) smarty template, whee

lol, and yes, simple things do amuse me

here's the template, specific to my module:
<{ section name=j loop=$multiple_array }>
    <
table align='center' cellpadding='2'>
    <
tr>
    <
td>
    <
table align='center' width='100%' border='1' cellspacing='0' cellpadding='2'>
    <{ if 
$multiple_array[j].lang_b_unit != 'both' }>
        <
tr>
        <
td width='100%' align='center' colspan='6'><b><{$multiple_array[j].lang_mbiz_unit}>b>td>
        tr>
    <{ /if }>
    <
tr>
    <
td align='center'><b><{ $multiple_array[j].lang_date }>b>td>
    <
td align='center'><nobr><b><{ $multiple_array[j].lang_adoption_notice }>b>nobr>td>
    <
td align='center'><nobr><b><{ $multiple_array[j].lang_style }>b>nobr>td>
    <
td width='100%' align='center' colspan='2'><nobr><b><{ $multiple_array[j].lang_changes }>b>nobr>td>
    tr>
    <{ 
section name=i loop=$multiple_array[j].lang_while_val }>
        <
tr>
        <
td align='center'><{ $multiple_array[j].lang_while_val[i].signin_date }>td>
        <
td align='center'><nobr><b><a href='index.php?op=Detailed&anumber=<{ $multiple_array[j].lang_while_val[i].adoption_notice }>'><{ $multiple_array[j].lang_while_val[i].adoption_notice }>a>b>nobr>td>
        <
td align='center'>
        <{ 
$multiple_array[j].lang_while_val[i].styles }>
        td>
        <
td align='center' colspan='2'><nobr><{ $multiple_array[j].lang_while_val[i].changes }>nobr>td>
        tr>
    <{ /
section }>
    <
tr><td <{$multiple_array[j].lang_colspan}> align='left'>
    <{ if 
$multiple_array[j].lang_worklogrows 10 }>
        <
table width='100%'><tr>
        <
td <{$multiple_array[j].lang_colspan}> align='left'><a href='index.php?op=View_Only&b_unit=csw&start=$finish'><b><{$multiple_array[j].lang_viewnext}>b>a>td>tr>table>
        td><td <{$multiple_array[j].lang_colspan}> align='right'>
    <{ /if }>
    <
table width='100%'><tr>
    <
td <{$multiple_array[j].lang_colspan}> align='right'><a href='index.php?op=Submit_Form'><b><{$multiple_array[j].lang_addnew_an}>b>a>td>tr>table>
    td>tr>
    table>
    td>tr>
    table>
    <
br>
<{/
section}>



$multiple_array is a sizeable array that is dynamically expansive, and smarty works great with it

example of how i populate $multiple_array:
$workingarray = array('lang_worklogrows'=>$worklogrows,
                          
'lang_b_unit'=>$b_unit,
                          
'lang_mbiz_unit'=>$mbiz_unit,
                          
'lang_while_val'=>$whilearray,
                          
'lang_colspan'=>$colspan,
                          
'lang_arraycount'=>$arraycount,
                          
'lang_date'=>'Date',
                          
'lang_adoption_notice'=>'Adoption Notice #',
                          
'lang_style'=>'Style',
                          
'lang_changes'=>'Changes',
                          
'lang_viewnext'=>'View Next 10 Results',
                          
'lang_addnew_an'=>'Add New Adoption',
                          
'lang_style'=>'Style');
    
$xoopsTpl->append('multiple_array',$workingarray);



this is what the array looks like when it's filled (it's been populated twice):
Array (2)
=> Array (12)
  
lang_worklogrows => 3
  lang_b_unit 
=> csw
  lang_mbiz_unit 
=> Casualwear
  lang_while_val 
=> Array (3)
    
=> Array (4)
      
signin_date => 4/30/04
      adoption_notice 
=> 04-P638
      styles 
=> P160<br>P161
      changes 
=> New Style
    1 
=> Array (4)
      
signin_date => 4/30/04
      adoption_notice 
=> 04-P639
      styles 
=> P161<br>T238
      changes 
=> Color Add pre-load
    2 
=> Array (4)
      
signin_date => 3/09/04
      adoption_notice 
=> 04-839
      styles 
=> Multi
      changes 
=> Pricing
  lang_colspan 
=> colspan='6'
  
lang_arraycount => 3
  lang_date 
=> Date
  lang_adoption_notice 
=> Adoption Notice #
  
lang_style => Style
  lang_changes 
=> Changes
  lang_viewnext 
=> View Next 10 Results
  lang_addnew_an 
=> Add New Adoption
=> Array (12)
  
lang_worklogrows => 0
  lang_b_unit 
=> prt
  lang_mbiz_unit 
=> Printables
  lang_while_val 
=> empty
  
lang_colspan => colspan='6'
  
lang_arraycount => 0
  lang_date 
=> Date
  lang_adoption_notice 
=> Adoption Notice #
  
lang_style => Style
  lang_changes 
=> Changes
  lang_viewnext 
=> View Next 10 Results
  lang_addnew_an 
=> Add New Adoption




oh, and i forgot to mention, i'm fairly novice with arrays as well, thus my giddiness when i finally made it work...!


okay, i'm done patting myself on the back

if you see a better way to setup the template, please let me know, as i said, i'm new to this so i probably made a redundant error

2
Herko
Re: smarty is pretty kick*ss
  • 2004/5/6 19:28

  • Herko

  • XOOPS is my life!

  • Posts: 4238

  • Since: 2002/2/4 1


Awesome job!! Congrats

Herko

3
intel352
Re: smarty is pretty kick*ss
  • 2004/5/6 19:38

  • intel352

  • Module Developer

  • Posts: 824

  • Since: 2003/11/23


hehe, thanks

4
ralf57
Re: smarty is pretty kick*ss
  • 2004/5/6 21:49

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


Nice job,
i'd like to suggest you to use
<{$smarty.const._xx_langconstant}>

instead of assigning lang constants.
This will save you a lot of time.
Keep up the good work!

5
fatman
Re: smarty is pretty kick*ss
  • 2004/5/6 22:47

  • fatman

  • Friend of XOOPS

  • Posts: 176

  • Since: 2003/12/13


Smarty does kick butt. I can't imagine not using it. Especially because I work with designers who do not know php.

Personally I like using smarty's <{ foreach }> rather than sections, but your example above does show off how powerful smarty can be.

Here is an example of how you can use your smarty output with foreach instead of sections
<{foreach item=item key=key from=$multiple_array}>

  <{
$item.lang_worklogrows}> <br/>
  <{
$item.lang_mbiz_unit}> <br />
  
  <{foreach 
item=subitem key=subkey from=$item.lang_while_val}>
     <{
$subitem.signin_date}>
  <{/foreach}>

<{/foreach}>


That example isn't using your full array, but perhaps you get the picture. I just find <{ foreach }> a little cleaner for my scrambled brain to grasp.

6
intel352
Re: smarty is pretty kick*ss
  • 2004/5/7 3:21

  • intel352

  • Module Developer

  • Posts: 824

  • Since: 2003/11/23


@ralf, where would smarty pull those constants from, if i didn't assign? that's new to me, could you explain a bit further?

7
intel352
Re: smarty is pretty kick*ss
  • 2004/5/7 3:24

  • intel352

  • Module Developer

  • Posts: 824

  • Since: 2003/11/23


@fatman, the examples that i found which showed me how to use sections also showed foreach, i only chose sections because that was recommended

as for grasping how it all laid out, it took trial-and-error for me, lol, and i used the smarty debug popup to see how the arrays that i created were structured, so i could make sure i broke them down properly in the template


believe me, anything to do with an array is a bit hard for me to grasp, period, lol... so i struggle until i hit the right combination, lmfao

8
Dave_L
Re: smarty is pretty kick*ss
  • 2004/5/7 4:28

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Quote:
where would smarty pull those constants from


They would have to have been defined by define('xxxx', yyyy); in a .php file.

Normally the files that defines the language constants you're using are automatically included by Xoops, so they're available within a Smarty template with the $smarty.const tag.

9
GIJOE
Re: smarty is pretty kick*ss
  • 2004/5/7 5:47

  • GIJOE

  • Quite a regular

  • Posts: 265

  • Since: 2003/8/13


The feature of $smarty.const.CONSTNAME was implemented after Smarty 2.5 or 2.4

XOOPS <= 2.0.2 uses Smarty 2.3.0
XOOPS >= 2.0.3 uses Smarty 2.5.0

If you can cut off the users of XOOPS prior to 2.0.3, you may use the feature.
But I'll keep to assign language constants for users who has some reasons why he don't update XOOPS. (too many hacks or so on)

10
intel352
Re: smarty is pretty kick*ss
  • 2004/5/7 11:15

  • intel352

  • Module Developer

  • Posts: 824

  • Since: 2003/11/23


good to know guys, thanks

Login

Who's Online

323 user(s) are online (219 user(s) are browsing Support Forums)


Members: 0


Guests: 323


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