Working with pages with feeds

steelej's Avatar

steelej

13 Sep, 2012 09:36 PM

I'm using an index block for a content type. Each of the pages get's its content from a feed block. I'm trying to use this index block to format a catalog of the pages. I'm having no luck as each page contains the feed in its entirety and I'm having trouble finding an identifier in the page that will allow me to target and winnow out the data appropriate to the individual listing.

  1. 1 Posted by Ryan Griffith on 14 Sep, 2012 12:08 PM

    Ryan Griffith's Avatar

    Hi,

    What you will want to do is use xPath to match the lname field within the Page's Data Definition with the corresponding lname element within your feed. Let's try the following:

    #set ( $assets = $_XPathTool.selectNodes($contentRoot,'/system-index-block/system-page'))
    
    #foreach ($asset in $assets)
        ## Record the lname entered within the Page
        #set ( $pageLname = $_XPathTool.selectSingleNode($asset, "system-data-structure/lname").value )
    
        ## Get the expert information that corresponds to the lname entered on the page
        #set ( $expertData = $_XPathTool.selectSingleNode($asset, "system-data-structure/expertfeed/content/system-page/expert[lname = '${pageLname}']") )
    
        #set ( $fname = $expertData.getChild("fname").value )
        #set ( $lname = $expertData.getChild("lname").value )
        #set ( $title = $expertData.getChild("title").value )
        #set ( $expertise = $expertData.getChild("expertise").value )
    
        <h3>${fname} ${lname}</h3><br />
        <p class="italic">${title}</p>
        <p><strong>Expertise:&#160;</strong>${expertise}</p>
    #end
    
  2. 2 Posted by steelej on 14 Sep, 2012 12:28 PM

    steelej's Avatar

    Ryan, thanks. This is really helpful. I was hard-pressed to figure this out. I need also to pull the path to the pages. Can you show me? Also, for some reason , the first expert, Bhatti, is showing twice.

  3. 3 Posted by Ryan Griffith on 14 Sep, 2012 12:40 PM

    Ryan Griffith's Avatar

    Not a problem. Because you are using a Content Type Index Block, your base asset used for the Asset Factory is also being picked up. Here's an updated version that adds in some extra checking as well as compares the the two last names in lower case (to avoid some potential entry issues):

    #set ( $assets = $_XPathTool.selectNodes($contentRoot,'/system-index-block/system-page'))
    #set ( $charLower = 'abcdefghijklmnopqrstuvwxyz' )
    #set ( $charUpper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' )
    
    #foreach ($asset in $assets)
        ## Record the lname entered within the Page
        #set ( $pageLname = $_XPathTool.selectSingleNode($asset, "system-data-structure/lname").value )
    
        #if ( $pageLname != '' )
            ## Get the expert information that corresponds to the lname entered on the page
            #set ( $expertXpath = "system-data-structure/expertfeed/content/system-page/expert[translate(lname, '${charUpper}', '${charLower}') = '${pageLname.toLowerCase()}']" )
    
            #set ( $expertData = $_XPathTool.selectSingleNode($asset, $expertXpath) )
    
            #if ( $expertData )
                #set ( $fname = $expertData.getChild("fname").value )
                #set ( $lname = $expertData.getChild("lname").value )
                #set ( $title = $expertData.getChild("title").value )
                #set ( $expertise = $expertData.getChild("expertise").value )
    
                <h3>${fname} ${lname}</h3><br />
                <p class="italic">${title}</p>
                <p><strong>Expertise:&#160;</strong>${expertise}</p>
            #end
        #end
    #end
    
  4. 4 Posted by steelej on 14 Sep, 2012 12:55 PM

    steelej's Avatar

    Ryan, thanks. Can you help with one more thing, I need to link the names to the pages. How do I pull the path to the pages?

  5. 5 Posted by Ryan Griffith on 14 Sep, 2012 01:05 PM

    Ryan Griffith's Avatar

    In your foreach, you can grab the page's link as follows:

    $asset.getChild('link').value

  6. 6 Posted by steelej on 14 Sep, 2012 01:09 PM

    steelej's Avatar

    Thanks again. I was thinkiing I needed to move up in the path to get back to the system-page. I really appreciate your help. I'm usally not this helpless with Velocity but this one was a little more complicated than the usual.

  7. steelej closed this discussion on 14 Sep, 2012 01:09 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