diff Lib/IMPL/Web/View/TTControl.pm @ 342:1090c1dd7429

TTControl: added a helper method 'CreateControlFromTemlpate'
author cin
date Wed, 03 Jul 2013 03:53:12 +0400
parents 71221d79e6b4
children 9bdccdf1f50b
line wrap: on
line diff
--- 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__