Home : General : Perl Programming :

General: Perl Programming: Re: [courierb] HTML::Template to GT::Template: Edit Log

Here is the list of edits for this post
Re: [courierb] HTML::Template to GT::Template
This is untested but might work:

sub display_cart {
my ($cgi, $session) = @_;

# getting the cart's contents
my $vars;
$vars->{total_price} = 0;

foreach my $product ( @{$session->param('CART')} ) {
$product->{prod_subtotal} = $product->{price} * $product->{quantity};
$vars->{total_price} += $product->{prod_subtotal};
push @($vars->{cart_loop}), $product;

require GT::Template;
return GT::Template->parse('html.tmpl', $vars);

and your template:

<%if cart_loop%>
<p>Here are your cart:</p>
<td>Unit Price</td>
<td>Product Subtotal</td>
<%loop cart_loop%>
<td colspan="3">Sub Total</td><td><%total_price%></td>
<p>There are no items in your cart yet</p>

Make sure you check out the pod for GT::Template. There's a *lot* you can do with it.


Last edited by:

Chaz: Oct 8, 2004, 2:53 PM

Edit Log: