atom feed - velocity - stumped
Hello,
I've tried to get this feed to work for a while, and I'm stumped. I haven't had any trouble with any other type of feed except this one. It's part of a page that uses velocity. Is it just me?
https://www.rollinsjobs.com/all_jobs.atom
I tried a simple script based on post in http://help.hannonhill.com/discussions/velocity-formats/96-velocity...
#set ( $feed = $_XPathTool.selectSingleNode($contentRoot, "feed") )
#set ( $entries = $_XPathTool.selectNodes($feed, "entry") )
<!-- $feed.getName() -->
<!-- #set ( $entries = $feed.getChildren() ) -->
<!-- $entries.size() -->
<div class="contentBox from-format">
#if ( $entries.size() > 0 )
<ul>
#foreach ( $item in $entries )
#if ( $item.getName() == "entry" )
#set ( $elements = $item.getChildren() )
#foreach ( $e in $elements )
#if ( $e.getName() == "title" )
#set ( $title = $e )
#end
#end
<li>$_EscapeTool.xml($title.value)</li>
#end
#end
</ul>
#end
</div>
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
1 Posted by Wing Ming Chan on 09 Jan, 2015 08:20 PM
Hi, Sarah,
"feed" is the root element. Therefore, you need to start your code like this:
I tested the code and it works.
Wing
2 Posted by Sarah Johnson L... on 09 Jan, 2015 09:15 PM
Hi Wing!
I made that little change, but it's still not coming through for me when I preview it while editing the format. I'm currently on v7.10.2 of cascade server. Not sure if that makes a difference or not.
Under Preview Options, I chose the feed block containing the feed above(https://www.rollinsjobs.com/all_jobs.atom), which shows perfectly fine
In the Velocity, I have this script with your change:
In the format window after I hit Test Format, I still get this:
<!-- $feed.getName() -->
<!-- -->
<!-- 0 -->
3 Posted by Wing Ming Chan on 09 Jan, 2015 09:19 PM
Sarah,
I am not into the habit of testing code like this. Instead, I just plug the block and format to a page region and view the page instead. I can see this result:
Wing
4 Posted by Ryan Griffith on 12 Jan, 2015 02:08 PM
Hi Sarah,
It sounds like you're running into an issue with the namespace that is being added to the feed, which is causing issues when you attempt to access the elements by their name. From what I am seeing when dumping
$contentRoot.getContent()
is an Atom namespace without a prefix, which can be a pain to work with.Here is what I would do:
This will obtain all Elements with the local name of
entry
(so without the namespace here); this also saves you from needing the extra loop to traverse the children. To summarize, in the loop we're using the usualgetChild
method, but with the namespace of the entry Element so we can access it by justtitle
. More information about these Element methods can be found here.Another way to write this using the XPath Tool would be:
Please let me know if you have any questions.
Thanks!
5 Posted by Ryan Griffith on 12 Jan, 2015 02:11 PM
Also, here is a slightly more efficient version of the first example:
Since all entries have the same namespace, we only need to save it once.
6 Posted by Sarah Johnson L... on 12 Jan, 2015 07:04 PM
Thank you Ryan! I knew there had to be something off with the feed. I NEVER had a problem before. I'll give these solutions a try and report back if it works.
7 Posted by Sarah Johnson L... on 12 Jan, 2015 07:12 PM
Ryan, it worked! All I had to do to get the entries was...
That's all it took!!! THANK YOU!!!
This feed comes from PeopleAdmin, which I know other schools use for hiring and recruitment. I'm sure not I'm not the first or last to deal with feeds from them.
8 Posted by Ryan Griffith on 12 Jan, 2015 08:16 PM
Thank you for following up, Sarah. I am glad to hear the adjustment did the trick.
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!
Ryan Griffith closed this discussion on 12 Jan, 2015 08:16 PM.