Formating a Block Index
I am learning how to use velocity and move most of the stuff I have in velocity i am working to move to XSLT. So I am learning in more detail how to use velocity, I have a block file I am wanting to call in my format that I do not know how to call. Could I get some assistance with this?
Thanks!
- velocity-format.txt 1.61 KB
- xml-info.xml 15.2 KB
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 Ryan Griffith on 19 Apr, 2016 04:46 PM
Hi Fernando,
A couple of things that jump out at me:
$page
variable as the context. This will require addingsystem-data-structure
to your XPath:$links.size()
is greater than 0 prior to looping to avoid Null Pointer errorsPlease let me know if you have any questions.
Thanks!
2 Posted by Fernando on 20 Apr, 2016 04:31 PM
Should I add the system-data-structure to the $page variable? or would it be fine in the $links variable?
How would I check if the link size is greater than 0 prior to looping?
Thanks for all of the help!
3 Posted by Ryan Griffith on 20 Apr, 2016 06:29 PM
Hi Fernando,
I added "system-data-structure" to the XPath used to obtain the links so it should not be necessary to add it anywhere else.
You would use
$links.size()
in an#if
statement:Please let me know if you have any questions.
Thanks!
4 Posted by Fernando on 20 Apr, 2016 07:41 PM
So how would call the outputting of links? on the line where I have <li></li>? I tried doing "<li>$_SerializerTool.serialize($links, true)</li>" but it didnt work. It was not rendering the right information.
5 Posted by Ryan Griffith on 20 Apr, 2016 08:13 PM
Hi Fernando,
This would depend on which XPath you chose to use. Also, you will be doing this within a
#foreach
loop.In this case, you can use
$link.getChild("content").getChild("system-symlink").value
OR$_XPathTool.selectSingleNode($link, "content/system-symlink").value
.In this case, you would simply use
$link.value
.Please let me know if you have any questions.
Thanks!
6 Posted by Fernando on 22 Apr, 2016 02:15 PM
I am getting close but I do not think i am quite there. This is what I am currently working on.
<ul>
#foreach ( $link in $links )
#if ($links.size() > 0)
#set($links = $_XPathTool.selectNodes($page, "system-data-structure/related/links/links-list/content/system-data-structure/link"))
#end
<li>$link.getChild("content").getChild("system-symlink").value</li>
#end
</ul>
It is showing me blank whenever I see the result of that. Am I missing something ?
Thanks for all of the help
7 Posted by Ryan Griffith on 22 Apr, 2016 02:59 PM
Hi Fernando,
You are definitely getting close, but need to restructure this code a bit. When you have a moment, give the following a try and let me know how it works out:
Please let me know if you have any questions.
Thanks!
8 Posted by Fernando on 22 Apr, 2016 03:29 PM
I got this error whenever I put that code in, not sure what happened since the Error line is 41 and my script is only 38 lines long.
Thanks again for the help!
9 Posted by Ryan Griffith on 22 Apr, 2016 07:45 PM
Hi Fernando,
It sounds like the XML validation during rendering does not like the parameters in those links; the ampersands specifically. When you have a moment, try adjusting the following:
to:
This should properly escape the ampersands.
Please let me know if you have any questions.
Thanks!
10 Posted by Fernando on 25 Apr, 2016 01:40 PM
Got it to work! At first it was only rendering the links so I did some changes.
And it works!! Thanks for all of the help!
Fernando closed this discussion on 25 Apr, 2016 01:40 PM.