From 0ffb94b48c8c9183805633241f53bd0b0f66d176 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 28 Oct 2010 18:01:28 +0200 Subject: [PATCH] =?utf8?q?Unterst=C3=BCtzung=20f=C3=BCr=20Variablenzugriff?= =?utf8?q?e=20auf=20Objekte/Hashes=20in=20Druckvorlagen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Wenn z.B. SL::Order->order_details $form->{ORDER_OBJ} auf eine Instanz von SL::DB::Order setzt, so kann im Template wie folgt darauf zugegriffen werden: Kunddenname: <%ORDER_OBJ.customer.name%> --- SL/Template/Simple.pm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/SL/Template/Simple.pm b/SL/Template/Simple.pm index d7a7c3525..8ad622043 100644 --- a/SL/Template/Simple.pm +++ b/SL/Template/Simple.pm @@ -10,6 +10,8 @@ package SL::Template::Simple; use strict; +use Scalar::Util qw(blessed); + # Parameters: # 1. The template's file name # 2. A reference to the Form object @@ -91,7 +93,19 @@ sub _get_loop_variable { my $form = $self->{form}; my $value; - if (($get_array || @indices) && (ref $form->{TEMPLATE_ARRAYS} eq 'HASH') && (ref $form->{TEMPLATE_ARRAYS}->{$var} eq 'ARRAY')) { + if ($var =~ m/\./) { + $value = $form; + for my $part (split(m/\./, $var)) { + if (ref($value) =~ m/^(?:Form|HASH)$/) { + $value = $value->{$part}; + } elsif (blessed($value) && $value->can($part)) { + $value = $value->$part; + } else { + $value = ''; + last; + } + } + } elsif (($get_array || @indices) && (ref $form->{TEMPLATE_ARRAYS} eq 'HASH') && (ref $form->{TEMPLATE_ARRAYS}->{$var} eq 'ARRAY')) { $value = $form->{TEMPLATE_ARRAYS}->{$var}; } else { $value = $form->{$var}; -- 2.20.1