foreach block is bleeding into the next block...

Nando's Avatar

Nando

13 Jul, 2016 12:57 PM

I have 2 blocks on the page, 1 is a standard xhtml block and the other is a structured data block built using a data definition.

I'm trying to get the data def name used for the block but the 2nd block always shows the 1st block info.

For example, if the data def block is first I get the correct data def name for block 1 and the same data def name for block 2 - block 2 doesn't have a data def so that's wrong. If the standard xhtml block is first, I get no data def name for both blocks, which is still wrong bc block 2 has a data def...

#import('site://Nova/_cascade/formats/bootstrap/setPath')##
#set ($page = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block/calling-page/system-page"))##
#set ($data = $page.getChild("system-data-structure"))##
#set ($blocks = $_XPathTool.selectNodes($data, "content-block"))##
#set ($customblockformat = $data.getChild("aoptions").getChild("cblockformat").value)
##
#if($blocks.size() > 0)##
##
#if($customblockformat != "")
###if(!$_PropertyTool.isNull($customblockformat) || $customblockformat != "" )
#import("${customblockformat}")
#else
##
#foreach ($block in $blocks)
#set ($blockpath = $data.getChild("content-block").getChild("path").value)
#set ($blocksite = $data.getChild("content-block").getChild("site").value)
#set($locatedblock = $_.locateBlock($blockpath, $blocksite))
##$_PropertyTool.outputProperties($locatedblock)
#set ($feedblock = $_XPathTool.selectSingleNode($data, "content-block/content/rss/channel/link").value)
##
#if($blockpath.contains("/_cascade/blocks/index/staff"))
##
#if($blockpath.contains("idep"))
#import("site://Nova/_cascade/formats/bootstrap/blocks/index/staff/idep")
#end
##
#elseif($feedblock.contains("nsunews"))
#import("site://Nova/_cascade/formats/bootstrap/nsuinternal/feedblock")
##
#elseif($blockpath.contains("/_cascade/blocks/index/structured-data"))##
#set ($comboname = $data.getChild("content-block").getChild("name").value)
#set ($combodata = $_XPathTool.selectSingleNode($data, "content-block/content/system-index-block"))##
#import("site://Nova/_cascade/formats/bootstrap/blocks/index/${comboname}")
##
#elseif($blockpath.contains("/_cascade/blocks/index/sitemaps"))##
#set ($combodata = $_XPathTool.selectSingleNode($data, "content-block/content/system-index-block"))##
#import("site://Nova/_cascade/formats/bootstrap/blocks/index/sitemaps")
##
#elseif($blockpath.contains("/_cascade/blocks/index/speakers"))##
#set ($combodata = $_XPathTool.selectSingleNode($data, "content-block/content/system-index-block"))##
#import("site://Nova/_cascade/formats/bootstrap/blocks/index/speakers")
##
#elseif($blockpath.contains("sdblock"))##
#set ($combodata = $_XPathTool.selectSingleNode($data, "content-block/content/system-data-structure"))##
#set ($comboname = $_XPathTool.selectSingleNode($data, "content-block/name").value)
#import("site://Nova/_cascade/formats/bootstrap/blocks/structured-data/${comboname}")
##
#elseif($blockpath != "/")
$locatedblock.dataDefinitionPath
##$_SerializerTool.serialize($block.getChild("content"), true)
##
#end## ## BLOCK PATH CONTAINS
#end## ## FOREACH
#end## ## CUSTOM FORMAT PATH
#end## ## BLOCK SIZE

thanks in advance!

  1. 1 Posted by Ryan Griffith on 13 Jul, 2016 01:04 PM

    Ryan Griffith's Avatar

    Hi Nando,

    I noticed when you set your $blockpath and $blocksite variables, you are using $data as the context and not $block from the #foreach:

    #set ($blockpath = $data.getChild("content-block").getChild("path").value)
    #set ($blocksite = $data.getChild("content-block").getChild("site").value)
    

    This would explain why you are only seeing the one result instead of the individual blocks. Instead, I think you want:

    #set ($blockpath = $block.getChild("path").value)
    #set ($blocksite = $block.getChild("site").value)
    

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by Nando on 13 Jul, 2016 01:13 PM

    Nando's Avatar

    wow, duh! thanks

  3. 3 Posted by Ryan Griffith on 13 Jul, 2016 07:21 PM

    Ryan Griffith's Avatar

    Not a problem at all, Nando. Glad to hear the proposed change helped out.

    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 13 Jul, 2016 07:21 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