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:

Code:
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:

Code:
<%if cart_loop%>
<p>Here are your cart:</p>
<br><br>
<table>
<tr>
<td>Qty</td>
<td>Product</td>
<td>Unit Price</td>
<td>Product Subtotal</td>
</tr>
<%loop cart_loop%>
<tr>
<td><%quantity%></td>
<td><%name%></td>
<td><%price%></td>
<td><%prod_subtotal%></td>
</tr>
<%endloop%>
<tr>
<td colspan="3">Sub Total</td><td><%total_price%></td>
</tr>
</table>
<%else%>
<p>There are no items in your cart yet</p>
<%endif%>

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

~Charlie

Last edited by:

Chaz: Oct 8, 2004, 2:53 PM

Edit Log: