# HG changeset patch # User cin # Date 1372809192 -14400 # Node ID 1090c1dd7429df4569577bfe5fd499b3ceb0df52 # Parent 70658970af15af9f922e90b37d13fdc1fd3403d3 TTControl: added a helper method 'CreateControlFromTemlpate' diff -r 70658970af15 -r 1090c1dd7429 Lib/IMPL/Web/View/TTControl.pm --- a/Lib/IMPL/Web/View/TTControl.pm Mon Jun 24 04:05:14 2013 +0400 +++ b/Lib/IMPL/Web/View/TTControl.pm Wed Jul 03 03:53:12 2013 +0400 @@ -138,6 +138,37 @@ } } +sub CloneContext { + my ($this) = @_; + + $this->context->localise(); + + my $args = { %{$this->context} }; + delete $args->{CONFIG}; + + $this->context->delocalise(); + + return TTContext->new($args); +} + +sub CreateControlFromTemplate { + my ($this,$template,$args) = @_; + + if (not ref($template)) { + return $this->context->stash->get([ + require => [ + $template + ] + ])->new($args); + } else { + return $this->new( + $template, + $this->CloneContext(), + $args + ); + } +} + 1; __END__