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

global param for assign

 
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
gerard
Smarty Regular


Joined: 18 Apr 2003
Posts: 84

PostPosted: Thu Aug 21, 2003 8:33 pm    Post subject: global param for assign Reply with quote

So that

{assign var="foo" value="bar" global="true"}

in an included template, will allow $foo to also be visible in parent templates.
Back to top
View user's profile Send private message
gerard
Smarty Regular


Joined: 18 Apr 2003
Posts: 84

PostPosted: Fri Aug 22, 2003 7:09 pm    Post subject: Reply with quote

Actually, I don't know how useful this would be as is. Templates appear to be processed sequentially, rather than, say, includes first. So, the global var wouldn't be set until after the {include} tag in the template.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Aug 27, 2003 1:57 am    Post subject: Reply with quote

As an experiment, I modified the _compile_include_tag() function in Smarty_Compiler.class.php. I had it recognize a new parameter called export and modified the production of $output such that if export is set (to any value), the included templates variables are merged back into the calling parents template variables using merge_array(). This isn't the same as global, as it exports only to the direct parent, but this could be chained along includes.

I don't know if it is really that useful--in fact it is a bit weird. Never-the-less, here it is as a diff against the current cvs.
Code:
Index: libs/Smarty_Compiler.class.php
===================================================================
RCS file: /repository/smarty/libs/Smarty_Compiler.class.php,v
retrieving revision 1.277
diff -u -r1.277 Smarty_Compiler.class.php
--- libs/Smarty_Compiler.class.php   20 Aug 2003 14:48:35 -0000   1.277
+++ libs/Smarty_Compiler.class.php   27 Aug 2003 01:52:24 -0000
@@ -876,6 +876,9 @@
             } else if ($arg_name == 'assign') {
                 $assign_var = $arg_value;
                 continue;
+            } else if ($arg_name == 'export') {
+                $export_var = $arg_value;
+                continue;
             }
             if (is_bool($arg_value))
                 $arg_value = $arg_value ? 'true' : 'false';
@@ -893,9 +896,14 @@
       
       
       $_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($export_var)) {
+           $output .= "\$this->_tpl_vars = array_merge(\$_smarty_tpl_vars, \$this->_tpl_vars);\n";
+      } else {
+           $output .= "\$this->_tpl_vars = \$_smarty_tpl_vars;\n";
+      }
+      $output .= "unset(\$_smarty_tpl_vars);\n";
 
         if (isset($assign_var)) {
          $output .= "\$this->assign(" . $assign_var . ", ob_get_contents()); ob_end_clean();\n";
@@ -2120,4 +2128,4 @@
 
 /* vim: set et: */
 
-?>
+?>
\ No newline at end of file

cheers.
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