0

I am keeping Asia as a parent element. Under that, I am keeping India and China as child elements. I want to fetch both of the countries by using velocity code.

Below is my code: I am using the method getChildren() and I am getting only the first child and am unable to get its two children.

I have parent element as continent and child elements as countries.

#foreach ($cur_continent in $continent.getSiblings())
#foreach($countries in $cur_continent.getChildren())
$countries.getData()
AstroCB
  • 12,337
  • 20
  • 57
  • 73
user3853393
  • 233
  • 4
  • 25

1 Answers1

0
  • What's the error message that you're getting - e.g. in the logfile?
  • As Pankaj mentions in the comments: make sure that you have an #end for every #foreach
  • If you want to know which methods you can call on each element, you can assume that they're java objects: Start with just writing $continent.getClass().getName(), see the result and look up the Java interface, so that you know what to call on each object.
  • Note that you use getSiblings and getChildren - probably expecting to have the same/similar results?

Once you went through this checklist, let us know what you found

Edit: Unfortunately the javadoc for com.liferay.portal.kernel.templateparser.TemplateNode isn't yet there, however, there's a difference between getSiblings and getChildren, and I'm always mixing them up - try both, alternatively, and let us know if one works. Currently you're using both at the same time (in different instructions). I believe that one of them will do what you want.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • Hi Kock Thanks for your response. Here my code contained #end also and i am not getting any error. My problem here is when i am using getChildren i am only getting the first child element(india) instead of getting all the childs(india,China). – user3853393 Jul 19 '14 at 12:27
  • Any one please help me on the above issue. – user3853393 Jul 19 '14 at 12:45
  • so, did you follow the suggestions that I gave? What's the result of $cur_continent.getClass().getName()? What's the interface of that class's getChildren() function? How does it differ from getSiblings()? – Olaf Kock Jul 19 '14 at 14:01
  • Yes i followed your instructions. The interface name is com.liferay.portal.kernel.templateparser.TemplateNode and the method getSiblings() and getChildren() both methods return type is List only. But i find one difference that is- getChildren() method is putting Arraylist(group of objects) inside list. I am confused how to fetch the Arraylist from that list and after that we have to fetch values from the arraylist. Please help me on this. – user3853393 Jul 19 '14 at 14:15
  • Any one help me on this please? – user3853393 Jul 20 '14 at 13:18