Displaying the parent folder's path of each system-page in an index block (folder type)

espanae's Avatar

espanae

22 Jul, 2016 07:02 PM

Hello, what's the best way to display the URL of a page, without the "index.php" at the end?

For example:
https://www.union.edu/academic/majors-minors/computational-methods/

Instead of:
https://www.union.edu/academic/majors-minors/computational-methods/...

In the past, we've displayed the parent folder's path using $currentPage.parentFolder.path but in this case, the pages are being generated from a folder type index block using a foreach loop:

#set ( $block = $_XPathTool.selectNodes($contentRoot, $xPath) )
#foreach ( $page in $block )
        #set ( $path = $page.getChild("path").value )
        <url>
            <loc>https://www.union.edu${_EscapeTool.xml($path)}.php</loc>
        </url>
#end

and parentFolder isn't a property available to the $page variable:

Properties:
 - value: String
 - textNormalize: String
 - text: String
 - parentElement: Element
 - getDescendants(Filter): Iterator
 - descendants: Iterator
 - getChildText(String): String
 - getChildText(StringNamespace): String
 - getChildTextNormalize(StringNamespace): String
 - getChildTextNormalize(String): String
 - getDescendants(Filter): Iterator
 - descendants: Iterator
 - additionalNamespaces: List
 - name: String
 - getNamespace(String): Namespace
 - namespace: Namespace
 - textTrim: String
 - getChildTextTrim(StringNamespace): String
 - getChildTextTrim(String): String
 - class: Class
 - getAttribute(StringNamespace): Attribute
 - getAttribute(String): Attribute
 - qualifiedName: String
 - children: List
 - getChildren(String): List
 - getChildren(StringNamespace): List
 - getChild(String): Element
 - getChild(StringNamespace): Element
 - namespaceURI: String
 - parent: Parent
 - contentSize: int
 - rootElement: boolean
 - parent: Parent
 - getContent(Filter): List
 - content: List
 - getContent(int): Content
 - getAttributeValue(StringNamespace): String
 - getAttributeValue(String): String
 - getAttributeValue(StringString): String
 - getAttributeValue(StringNamespaceString): String
 - getContent(Filter): List
 - getContent(int): Content
 - content: List
 - contentSize: int
 - namespacePrefix: String
 - document: Document
 - attributes: List
 - document: Document
 - isAncestor(Element): boolean

Any suggestions would be much appreciated.
Erik

  1. 1 Posted by Wing Ming Chan on 22 Jul, 2016 07:44 PM

    Wing Ming Chan's Avatar

    Erik,

    Will you consider simple string manipulation like the following?

    #set ( $block = $_XPathTool.selectNodes( $contentRoot, "//system-page" ) )
    
    #foreach ( $page in $block )
        #set ( $path = $_EscapeTool.xml( $page.getChild( "path" ).value ) )
        <url>
        #if( !$path.endsWith( '/index' ) )
            #set( $path =  $path + '.php' )
        #else
            #set( $path = $_StringTool.substringBefore( $path, "/index" ) )
        #end
        
            <loc>https://www.union.edu$path</loc>
        </url>
    #end
    

    Wing

  2. 2 Posted by espanae on 22 Jul, 2016 08:36 PM

    espanae's Avatar

    Yes, I thought about using string manipulation but didn't know how. Where did you learn about the endsWith() method?

    This code seems to do the trick so I should be all set.

    Thanks,
    Erik

  3. 3 Posted by Wing Ming Chan on 22 Jul, 2016 08:59 PM

    Wing Ming Chan's Avatar

Comments are closed, but you can 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