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?

Thanks,
-JET

  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.

    Thanks!

  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: http://ideas.hannonhill.com/forums/52559-ideas-for-cascade-server/s...

  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.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? 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