Import global Velocity format that then matches on a local macro

sbarre5's Avatar

sbarre5

04 Feb, 2015 09:59 PM

I've got two formats that I'm dealing with. One is a global, template-wide format and the other is a local, site-specific format. The site-specific format is what I have mapped to my default region and it imports the global format and also has a macro. The global format gets imported perfectly, however at the end of the global format, I'm calling the macro ( #local_block($content_block) ) that exists in my local format. The global format doesn't seem to be communicating back to my local format and rendering the macro ( #macro(local_block $content_block) ) that's on my local format. Any ideas why this would be happening?

Local format:


#import('site://WDG F1 - Velocity/_cms/velocity/default-region-velocity')
#macro(local_block $content_block)
    #set ($local_block_path = $_XPathTool.selectSingleNode($content_block, "path"))
    #set ($local_block = $_.locateBlock("${local_block_path.value}", $currentPageSiteName))
    #format_local_block($local_block)
#end

Global Format:


#set ($page_layout = $currentPage.getStructuredDataNode("page-layout"))
#set ($page_title = $_XPathTool.selectSingleNode($contentRoot,"//calling-page/system-page/title").value )
#set ($title_location = $page_layout.getChild("page-title-location").textValue)
#set ($page_columns = $page_layout.getChild("columns").textValue)
#set($column_1 = $_XPathTool.selectNodes($contentRoot, '//column-1/row/row-block'))
#foreach($row_block in $column_1) #set ($column_layout = $block.getStructuredDataNode("row/two-column-layout").textValue) #parse_row($row) #end #macro(parse_row $row) #set ($this_block_path = $_XPathTool.selectSingleNode($row, "path").value) #set ($row_block = $_.locateBlock("${this_block_path.value}", $currentPageSiteName)) #set ($row_setup = $_XPathTool.selectNodes($row_block, "content/system-data-structure/row")) #set ($number_of_columns = "") #set ($number_of_columns = $_XPathTool.selectSingleNode($row_setup,"columns")) #set ($column_blocks = $_XPathTool.selectNodes($contentRoot,'//column-1/row/row-block/content/system-data-structure/row/column-1/block') ) #if ($number_of_columns.value == 1 or $number_of_columns.value == 2 or $number_of_columns.value == 3) #if ($number_of_columns.value == 2 or $number_of_columns.value == 3) #foreach($content_block in $column_blocks) #set($path = $_XPathTool.selectSingleNode($content_block, "path").value) #if ($path != "/") #local_block($content_block) #end #end #end
#end

Any and all help would be greatly appreciated!

  1. 1 Posted by Ryan Griffith on 05 Feb, 2015 05:10 PM

    Ryan Griffith's Avatar

    Hi,

    Seems as though your local macro is not yet registered at the time it is being called.

    When you have a moment, try switching the #import and #macro directives in your local format and let me know if this changes anything.

    Something else you could try, is apply the global format to the page region and re-factor your global format to import the local one dynamically using perhaps the selected block's <site> value. Something like the following maybe:

    #set($path = $_XPathTool.selectSingleNode($content_block, "path").value)
    #if ($path != "/")
        #set($site = $_XPathTool.selectSingleNode($content_block, "site").value)
        #import("${site}/path/to/local-format")
        #local_block($content_block)
    #end
    

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by sbarre5 on 06 Feb, 2015 03:24 PM

    sbarre5's Avatar

    Ryan,

    I tried doing it both ways and unfortunately it doesn’t seem to be working.

    I tried to use the currentPageSiteName to get the local velocity since it will always be local to the current page that someone is on.

    This is my code:
    #import("site://${currentPageSiteName}/_cms/velocity/local-velocity”)

    I get the following error:
    An error occurred while rendering asset preview: The requested asset does not exist: Format #import with path 'site://${currentPageSiteName}/_cms/velocity/local-velocity' in templateValidation[line 7, column 1].

    Saundra Barrett
    Senior Web Developer
    Emory University, Web Design Group
    Office: 404-727-3437
    Cell: 404-670-1238

  3. 3 Posted by sbarre5 on 06 Feb, 2015 04:15 PM

    sbarre5's Avatar

    Actually – it worked! I’m still getting a grip on what I can pull out of things and where to run my logic – its a big difference from XSLT.

    Thank you so much for your help!

    Saundra Barrett
    Senior Web Developer
    Emory University, Web Design Group
    Office: 404-727-3437
    Cell: 404-670-1238

  4. 4 Posted by Ryan Griffith on 06 Feb, 2015 04:35 PM

    Ryan Griffith's Avatar

    Not a problem at all, Saundra. I am glad to hear you were able to get the code working.

    Velocity is definitely different, but fun to work with.

    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!

  5. Ryan Griffith closed this discussion on 06 Feb, 2015 04:35 PM.

  6. Ryan Griffith re-opened this discussion on 09 Feb, 2015 02:14 PM

  7. Ryan Griffith closed this discussion on 05 Mar, 2015 07:59 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