By comfixit on
Is there a way to create a temporary variable in one module or theme TPL file and check the state of that variable in another file when processing a single page?
Perhaps there is a way to set/read a custom variable in the session? What are some strategies I can use to accomplish this?
Comments
_
Either use variable_set/variable_get (http://api.drupal.org/api/function/variable_set/6) or set $_SESSION['your-variable-name'] for a session-specific scope.
variable_set and variable_get
variable_set and variable_get are sitewide, not user-based, so if you use them, keep that in mind.
Contact me to contract me for D7 -> D10/11 migrations.
Thank you for the tip. And
Thank you for the tip. And variable can be set and retrieved however it runs in a way that I did not expect.
I am overriding 2 view templates. In the first template which overrides (views-view-unformatted.tpl.php) it seems to try to print the row which gets its output from the template which overrides (views-view-fields.tpl.php). In that second template I print out some variables directly and also try to print the JTS variable I set which should print 1 the first time through the loop and 2 the second time. However when I run this code it shows only the 2 which suggests to me that Drupal is probably calculating the results for the variable at the end of this tpl page before applying the value when running the internal loops.
(views-view-unformatted.tpl.php)
(views-view-fields.tpl.php)
Please excuse the sloppy experimental state the code is in. However the output of the print $JT_State shows as 2 both times the loop is run.
I would like to eventually create a switch statement to act on the information differently depending on if its the first or second pass however if this behavior cannot be avoided I might need to attack the problem another way.
This works for me
in your function do the following
It won't save it in the database because it's not using the variable_set() function. Will only work for the current running script and then next time will revert to original value.
But, it will be available for variable_get() functions
I use it to override the default location for storing files. I like to use drupal's powerful file_* functions, but drupal checks to see the destination of the file if it is in the default file directory. So I use the above code to temporarily set the default_file_directory to the place I want to use.
Create a temporary global variable
Hi comfixit
global $variable
declare the variable
Set the value for the variable
$variable="your value";
where u want to accomplish this?
use
unset($variable);