drupal_eval() does not allow you to access context variable. but...I am currently working on a project which uses the module site_user_list and I wanted to use some variables in my template. The documentation of the module said I could use the variables from the $r array but I discovered that was not working. I found someone discovered the same problem and opened an issue: That same person also contributed a patch but I was unhappy with it. I provided my own. If you want to use drupal_eval() and allow the code inside that to access (read-only) some of your context variables, try this: Let's assume you want to eval the PHP code found in the variable $code. You might consider doing like this: $options = array('foo' => 'bar'); drupal_eval('<?php ' . $code . '?>'); This would mean that whatever PHP code found in $code would have no access to $options. This is why I recommend this: $options = array('foo' => 'bar'); drupal_eval('<?php $options = '. var_export($options, TRUE).'; ' . $code . '?>'); The var_export() function (php core) will create valid PHP code from your array. You assign that to another variable (could be called anything) and voila. This code will be executed and the values from your $options array becomes accessible (read-only) to your $code.
|
SearchDrupal ContributionsMake a Payment to Christian Roy |
Drupal has provided
Drupal has provided extremely well features and facilities to the users which is the main reason for migration of users to Drupal platform inorder to avail all opportunities present in Drupal.I think Drupal has defeated all its competitor in a very short time with its excellent features.
Post new comment