Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

[patch] Flag for {include} tag to keep vars

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
munzili
Smarty n00b


Joined: 13 Jun 2007
Posts: 1

PostPosted: Wed Jun 13, 2007 10:40 am    Post subject: [patch] Flag for {include} tag to keep vars Reply with quote

currently the {include file='template.tpl'} tag doesn't keep the vars that are defined in the 'template.tpl' file. It would be nice to have a possibility/flag to allow this, as a global template could be then used to define variables that can be used in multible files/templates then.

I created a patch for the Smarty_Compiler.class.php file to allow this optional flag

Code:

--- Smarty_Compiler.class.php   2007-03-07 23:12:46.000000000 +0100
+++ Smarty_Compiler.class.php2  2007-06-13 12:33:56.000000000 +0200
@@ -982,7 +982,10 @@
             } else if ($arg_name == 'assign') {
                 $assign_var = $arg_value;
                 continue;
+            } else if ($arg_name == 'b_keep_vars') {
+                continue;
             }
+         
             if (is_bool($arg_value))
                 $arg_value = $arg_value ? 'true' : 'false';
             $arg_list[] = "'$arg_name' => $arg_value";
@@ -994,14 +997,19 @@
             $output .= "ob_start();\n";
         }

-        $output .=
-            "\$_smarty_tpl_vars = \$this->_tpl_vars;\n";
-
-
+        if(!isset($attrs['b_keep_vars']) || !$attrs['b_keep_vars']) {
+            $output .=
+                "\$_smarty_tpl_vars = \$this->_tpl_vars;\n";
+        }
+     
         $_params = "array('smarty_include_tpl_file' => " . $include_file . ", 'smarty_include_vars' => array(".implode(',', (array)$arg_list)."))";
-        $output .= "\$this->_smarty_include($_params);\n" .
-        "\$this->_tpl_vars = \$_smarty_tpl_vars;\n" .
-        "unset(\$_smarty_tpl_vars);\n";
+        $output .= "\$this->_smarty_include($_params);\n";
+
+        if(!isset($attrs['b_keep_vars']) || !$attrs['b_keep_vars']) {
+            $output .=
+                "\$this->_tpl_vars = \$_smarty_tpl_vars;\n" .
+                "unset(\$_smarty_tpl_vars);\n";
+        }

         if (isset($assign_var)) {
             $output .= "\$this->assign(" . $assign_var . ", ob_get_contents()); ob_end_clean();\n";
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP