Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML:Template - Loops & globals 2

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
HI, I'm having major problems working out how to use this template module, i've read CPAN again & again & again & again, I can't understand it.

It says for access to global vars, use the global vars option with the new(); (as show above) , well I've searched the page and cannot find anywhere it showing this option being used.

does anyone know how to do it?

also I have 3 nested loops in my template, only the first one does anything, i'm assuming it's to do with this globals thing, but maybe that's not it, as I don't understand any of the explanation on CPAN for nested loops can anyone help ?

in the PERL
Code:
# Create Menu Arrays
my (@month_data,@year_data,@stat_data,@curstat);
    
# Set month index
my $mnth = -1;

# Loop each month     
foreach my $month (@months){
    $mnth++;
    if($month){        
        # Add Month Menu Option
        push @month_data, {month => $mnames[$mnth] };

        # Set year index     
        my $yr = -1;

        # Loop Years
        foreach my $year (@$month){
            if($year){        
                $yr++;
                # Create display year text
                my $dispyear = $yr + 2005;       
      
                # Add Year Menu Option   
                push @year_data, {year => $dispyear};   
                         
                # Loop Statement Array 
                foreach my $stat(@$year){  
                    foreach my $st ($stat){
                        if($st){
                            # Set date
                            my ($year,$month,$day) = split(/-/,substr($st->{'SDate'},0,10));
                            # Set html display
                            my $disp = "$day/$month/$year";
                            # Build each statement link
                            push @stat_data, {docid => $st->{'DocID'}, period => $disp};                            
                        }
                    }
                }
            }                   
        } 
    }           
}

# Add menu arrays to template
$template->param('month' => \@month_data);
$template->param('year'  => \@year_data);
$template->param('stat'  => \@stat_data);

# Set Current Statement Details      
if(@rs){
    # Set date
    my ($year,$month,$day) = split(/-/,substr($rs[0]->{'SDate'},0,10));    
    push @curstat, {disp => '$day/$month/$year' , docid => $rs[0]->{'DocID'}};
}
else{push @curstat,{disp => 'N/A' , docid => '0'};}

# Add current stat to template
$template->param('curstat' => \@curstat);
                
print "Content-type: text/html\n\n";

print $template->output;

in the template
Code:
<div id="menu">
        <div><div><div style="display:none;"><ul id="imenus0" style="width:95px; z-index:3;">
        <!--tmpl_loop name="month"-->
            <li  style="width:95px;"><a name="<tmpl_var name='month'>" style="text-decoration:none;"><!--tmpl_var name='month'--></a>
                <!--tmpl_loop name="year"-->
                    test<div><div style="width:65px;top:-18px;left:80px;"><ul style=""><li><a name=""><!--tmpl_var name='year'--></a><div><div style="width:140px;top:-18px;left:50px;"><ul style="">
                        <!--tmpl_loop name="stat"-->
                            <li><a name="<tmpl_var name='docid'>" onclick="getAjax('<tmpl_var name='url_to_https'>/commissions3.cgi','FA=VW&requireduser=$user&DOC=<tmpl_var name='docid'>','<tmpl_var name='period'>')">Period Ending <!--tmpl_var name='period'--></a></li>
                        <!--/tmpl_loop-->
                    </ul></div></div></li>
                <!--/tmpl_loop-->
            </ul></div></div>
        <!--/tmpl_loop--> 
        </li></ul><div style=\"clear:left;\"></div></div></div></div>

hope this makes sense to someone!
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
That is no problem at all. If it wasn't for the creation of these types of modules, I would still be in that same boat that you are.

I'm glad that you're really moving through the conversion now and did stick with it as you caught on to what it can/does do for your code and separation of presentation.

As always, pop something in the forums if you have questions. While I'm not on here as much as I'd like any longer, I do stop in regularly to see what's up.

- George
 
what it can/does do for your code and separation of presentation.
I just wished the Layout/Structure separation (tables->div) was as easy as code/presentation separation and worked properly!

It's been driving me mad trying to comply to CSS layout techniques when simple things like center/vertical align seems imposible and non-sensical.

But I'm soldiering on non-the-less, at least with the HTML in a template it's a bit easier to attempt to validate the HTML and to see what's going on.

Hope you not being around much is a sign you are being appreciated and well paid for your skills.

As always, kind regards
1DMF


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Actually, I took a jump out of the Perl world and back into J2EE development. So far it's been fun, but with this year's work looming above our team, it's going to be a busy one.

Good luck with the CSS compliance. Just remember though, it could be worse. You could be working with a team of "usability experts" that have never built anything that wasn't made specifically for print material. That is the hell that is my job right now.

- George
 
J2EE devel, you must be a wizard, the nearest I get is a bit of coldfusion!

Good luck, don't work too hard!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
No, not a wizard, just like to dabble across languages. I think I just like to cause myself headaches most of the time.

- George
 
Wanted to let you know, I've just finished the company re-write of the members area, all templates validate via W3C for X/HTML Transitional and no more ugly PERL code mixed with HTML.

(I haven't mastered symantecs with css/html separation but hey 1 step at a time :) )

A big thank you goes to George for all his help with the template module and of course all the other PERL heads who have helped - you know who you are, thank you.

[cheers]

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top