Velocity macro caching?

View: New views
2 Messages — Rating Filter:   Alert me  

Velocity macro caching?

by harin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have an issue where velocity seems to be caching a velocimacro. It could possibly be my template structure which shown below. When pages are loaded, velocity is rendering the wrong primarySection or secondarySection vm (as these exist in other templates).
To me the logic seems fine as it should call the macro which is on the page, but something is obviously going wrong somewhere. Can anyone see any faults which this method?

test.html:
   #macro(primarySection)

   #end

   #macro(secondarySection)

   #end

  #structure("landing")

In a global macro file i have:

  #macro(structure $structureName)
        #block("structures/${structureName}.vm")
  #end

  #macro(block $path)
        #if($path != "")
                #parse("/site/static/blocks/${path}")
        #end
  #end

And a vm which does the layout (landing.vm):
  <div class="yui-gc">
        <div class="yui-u first">
                <div class="yui-gc">
                        ## Left column
                        <div class="yui-u first">
                                #primarySection()
                        </div>
                       
                        ## Middle column
                        <div class="yui-u">
                                #secondarySection()
                        </div>
                </div>
        </div>
       
        ## Right column
    <div class="yui-u">
                #sponsorSidebar($sponsorSidebar)
        </div>
  </div>

My velocity properties:
  runtime.log.logsystem.class=org.apache.velocity.runtime.log.SimpleLog4JLogSystem
  runtime.log.logsystem.log4j.category=velocity
  runtime.log.reference.log.invalid=false
  file.resource.loader.cache=false
  velocimacro.library.autoreload=false
  velocimacro.permissions.allow.inline.to.replace.global=true
  velocimacro.permissions.allow.inline=true

Re: Velocity macro caching?

by Christopher Schultz-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Harin,

harin wrote:
> I have an issue where velocity seems to be caching a velocimacro. It could
> possibly be my template structure which shown below. When pages are loaded,
> velocity is rendering the wrong primarySection or secondarySection vm (as
> these exist in other templates).

I have had the same problem, where the first page evaluated that defines
a macro basically ends up setting that macro for the entire Velocity
subsystem. Templates with same-named macros had to be modified not to do
this (in 1.4, at least).

I always thought that a macro's "name" would essentially be qualified by
it's loading template, so a macro in foo.vm called bar would be
fully-qualified as something like "foo:bar". When called from foo.vm, no
qualification is necessary.

Actually, it would make more sense to me if macros defined in a template
were always considered local, so they couldn't be overridden.

Just my two cents.

-chris



signature.asc (266 bytes) Download Attachment