Velocity Private Variables

Justin "JET" Turner's Avatar

Justin "JET" Turner

21 Jul, 2014 04:37 PM

I have been working with some macros that occasionally need to be recursive, so I am looking for a way to declare private variables within the macros.

I found some information here: stack overflow about using a $macro variable, but it requires a configuration change. macro.provide.scope.control = true from apache source information

Has anyone tried to make this change or found other ways to work around issues with occasionally needing private variables?


  1. 1 Posted by Ryan Griffith on 22 Jul, 2014 12:23 PM

    Ryan Griffith's Avatar

    Hi Justin,

    It sounds like this change may be limited to just the $macro variable within macro definitions, which seems similar to the $foreach scope variable that is available within foreach loops. Unfortunately, it may be very difficult to tell how a change like this would affect Velocity Formats for existing clients, because every Format can be so unique.

    If you feel this would be a good feature to add to Velocity Formats, I highly recommend adding a suggestion on our Idea Exchange for others to vote up and/or comment on. This would help us determine use cases and overall popularity of the functionality.

    For the variables that need to be scoped, you could perhaps try resetting the value at the end of the macro, or before it is called recursively.

    Please let me know if you have any questions.


  2. 2 Posted by Justin "JE... on 22 Jul, 2014 12:54 PM

    Justin "JET" Turner's Avatar

    Thanks for the info Ryan. I didn't realize there was a $foreach variable scope already.

    I created the following idea on the Idea Exchange:

  3. 3 Posted by Ryan Griffith on 22 Jul, 2014 01:11 PM

    Ryan Griffith's Avatar

    Perfect, thank you for posting to the Idea Exchange, Justin.

    I didn't realize there was a $foreach variable scope already.

    Yup, definitely useful if you need to know if there are more items to loop over, or the total count. More information about this scope variable can be found here.

    I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

  4. Ryan Griffith closed this discussion on 22 Jul, 2014 01:11 PM.

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac


26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM