Velocity error checker causing problems

webadmin's Avatar

webadmin

30 Jun, 2016 02:49 PM

Here's my Velocity script:

## Macro for displaying first few sentences of an article
#macro (displayArticle $articleText $wordCount)
#set ($textArray = $articleText.split(" "))
#set ($displayText = "")
#set ($counterVal = 0)
#foreach ($textItem in $textArray)
#if ($counterVal >= $wordCount)
#break
#end
#set ($displayText = $displayText + " " + $textItem)
#set ($counterVal = $counterVal + 1)
#end
#set ($displayText = $displayText + "...")
$displayText
##$_SerializerTool.serialize($displayText, false)
#end

## Macro for displaying the first article
#macro (displayFirst $image $title $text $link)
<section class="fullwidth_section light_section">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <div class="sc_section">
                    <div class="sc_content container">
                        <h2 class="sc_title sc_title_regular sc_align_center">Recent News</h2>
                        <br />
                        <div class="sc_columns sc_columns_count_2">
                            <div class="col-sm-6 sc_column_item">
                                <figure class="sc_image sc_image_shape_square">
                                    <img src="/render/file.act?path=site://Gatekeeper-News/$image" alt="" />
                                </figure>
                            </div>
                            <div class="col-sm-6 sc_column_item">
                                <div class="sc_section">
                                    <div class="sc_contact_info">
                                        <h4 class="sc_contact_title">$title</h4>
                                    </div>
                                    <p>
                                        #displayArticle($text.value 30)
                                        link is $link
                                    </p>
                                    
                                    <a href="$link" class="sc_button sc_button_square sc_button_bg_underline  sc_button_iconed">
                                        read more
                                        <span class="sc_button_iconed icon-right"></span> 
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
#end

## Macro for displaying the secondary articles
#macro (displaySecondary $image $title $text $link $articleCounter)

    ## If it's the first of the secondary articles, you need the header info.
    #if ($articleCounter == 1)
<section class="fullwidth_section news_section">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <div class="sc_section">
                    <div class="sc_content container">
                        <div class="sc_blogger layout_news template_news sc_blogger_horizontal">
                            <div class="columns_wrap">
    #end
                                <div class="col-sm-4 column_item_$articleCounter">
                                    <div class="post_item post_item_news sc_blogger_item">
                                        <div class="post_featured">
                                            <div class="post_thumb">
                                                <img src="/render/file.act?path=site://Gatekeeper-News/$image" alt="" />
                                                <div class="hover_wrap">
                                                    <div class="link_wrap">
                                                        <a class="hover_link icon-link" href="#"></a>
                                                        <a class="hover_view icon-resize-full" href="/render/file.act?path=site://Gatekeeper-News/$image" title="$title"></a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <h4 class="post_title sc_title sc_blogger_title">$title</h4>            
                                        <div class="post_content sc_blogger_content">
                                            <div class="post_descr">
                                                <p>#displayArticle($text.value 15)</p>
                                                <a href="/render/file.act?path=site://Gatekeeper-News/$link" class="sc_button sc_button_square sc_button_bg_underline  sc_button_iconed ">
                                                    Learn more
                                                    <span class="sc_button_iconed icon-right"></span>
                                                </a>
                                            </div>
                                        </div>  
                                    </div>      
                                </div>
    ## If it's the last of the secondary articles, you need the footer info.
    #if ($articleCounter == 3)
                            </div>
                        </div>      
                    </div> 
                </div>
            </div>
        </div>
    </div>
</section>
    #end
#end

## Macro for populating articles for news
#macro (populateArticles)
## Abstract out the "system-index-block" node
#set ($sib = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block"))

## Gather "page" nodes
#set ($pages = $_XPathTool.selectNodes($sib, "system-page"))

#set ($articleCounter = 0)
## Loop through pages
#foreach ($page in $pages)
## Gather pages
##set ($link = $_XPathTool.selectSingleNode($file, "dynamic-metadata[name='Link']/value").value)
#set ($title = $_EscapeTool.xml($page.getChild("title").value))
#set ($createDate = "nothing")
#set ($createDate = $_XPathTool.selectSingleNode($page, "dynamic-metadata[name='Date']/value").value)
#if ($createDate == "nothing")
#set ($createDate = $currentPage.createdOn)
#end
#set ($dateFormat = $_DateTool.getDateFormat("MM-dd-yyyy", $_DateTool.getLocale(), $_DateTool.getTimeZone()))
#set ($createDate = $dateFormat.parse($createDate))
#set ($author = $page.getChild("author").value)
#set ($link = $page.getChild("link").value)
#set ($pageSD = $page.getChild("system-data-structure"))
#set ($desc = $pageSD.getChild("Default"))
#set ($imageBlock = $pageSD.getChild("Image"))
#set ($image = ${imageBlock.getChild('path').value})

#if ($articleCounter == 0)
#displayFirst($image $title $desc $link)
#elseif ($articleCounter < 4)
#displaySecondary($image $title $desc $link $articleCounter)
#else
#break
#end

#set ($articleCounter = $articleCounter + 1)
#end
#end

#populateArticles()

The issue is with the "#displaySecondary" macro. I'm needing to do something a bit different on each iteration of the macro. On the first iteration, I need those starting lines of code, and on the last iteration, I need those ending lines. However, the system won't let me do that, because it thinks I'm not ending some div tags. I know the code is fine on its own, because I tested that. There's not a missing div tag. I've also commented out those starting and ending lines of code, and it works fine. I tried wrapping them in <!--#protect ... #protect-->. That made it run, but it doesn't output the code I need it to output. How do I make it just run the code as-is without warning me?

  1. 1 Posted by webadmin on 30 Jun, 2016 03:34 PM

    webadmin's Avatar

    Sorry. Found my error. You can close this.

  2. Tim closed this discussion on 30 Jun, 2016 03:35 PM.

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

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

 

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