I wonder if anyone here could help me to covert parser from HTML::Template to GT::Template
i now only able to do a single string replacement. while has difficulty in loop.
the orginal code is
sub display_cart {
my ($cgi, $session) = @_;
# getting the cart's contents
my $cart = $session->param("CART") || [];
my $total_price = 0;
my $RV = qq~<table><tr><th>Title</th><th>Price</th><th>Quantity</th></tr>~;
if ( $cart ) {
my $idx = 0;
for my $product ( @{$cart} ) { $idx++;
#$total_price += $product->{price};
$subtotal = ($product->{price})*($product->{quantity});
$total_price += $subtotal;
# my $idx = 0;
$RV .= qq~<tr><td>$product->{name}</td><td>$product->{price} ($idx++ $idx )</td><td>$subtotal----$product->{quantity}</td></tr>~;
}
} else {
$RV .= qq~
<tr>
<td colspan="2">There are no items in your cart
yet</td>
</tr>~;
}
$RV .= qq~
<tr>
<td><b>Total Price:::</b></td>
<td><b>$total_price></b></td>
</tr></table>~;
return $RV;
}
i now only able to do a single string replacement. while has difficulty in loop.
the orginal code is
sub display_cart {
my ($cgi, $session) = @_;
# getting the cart's contents
my $cart = $session->param("CART") || [];
my $total_price = 0;
my $RV = qq~<table><tr><th>Title</th><th>Price</th><th>Quantity</th></tr>~;
if ( $cart ) {
my $idx = 0;
for my $product ( @{$cart} ) { $idx++;
#$total_price += $product->{price};
$subtotal = ($product->{price})*($product->{quantity});
$total_price += $subtotal;
# my $idx = 0;
$RV .= qq~<tr><td>$product->{name}</td><td>$product->{price} ($idx++ $idx )</td><td>$subtotal----$product->{quantity}</td></tr>~;
}
} else {
$RV .= qq~
<tr>
<td colspan="2">There are no items in your cart
yet</td>
</tr>~;
}
$RV .= qq~
<tr>
<td><b>Total Price:::</b></td>
<td><b>$total_price></b></td>
</tr></table>~;
return $RV;
}