Large menu - foreach with different element tags (div. ul, li) on children/parents

matthew.norton's Avatar

matthew.norton

10 Sep, 2012 08:11 PM

We are building a very large menu that we would like to import into the CMS through velocity. We have a working PHP version, however, we need to include this menu format in multiple places and would prefer to set it up as a format block in the CMS. This would allow us to make changes as needed in one file instead of many.

Attached is the XML, Velocity attempt, working PHP version, HTML of final result and an image display.

Has anyone filtered through a foreach loop and used a combination of <div> and <ul><li> intermittently in their script? We believe we are almost their, any assistance would be appreciated.

Matthew

  1. 1 Posted by Ryan Griffith on 11 Sep, 2012 02:32 PM

    Ryan Griffith's Avatar

    Hi Matthew,

    Quick question, would there ever be a case where there will be a page or symlink at the first or second level (ie Heading and Subheading)?

  2. 2 Posted by matthew.norton on 11 Sep, 2012 02:40 PM

    matthew.norton's Avatar

    Hi Ryan,

    No at this point only folders with index pages at those levels. Is it possible to have a page/symlink with children in the system?

  3. 3 Posted by Ryan Griffith on 11 Sep, 2012 02:43 PM

    Ryan Griffith's Avatar

    Thank you, that helps a bit. Wasn't sure how flexible those two levels would need to be.

    Only Folders would have children, Pages and Symlinks have siblings.

  4. 4 Posted by Ryan Griffith on 11 Sep, 2012 03:25 PM

    Ryan Griffith's Avatar

    This might be a long shot, but let's see how the attached Format works out.

    Note: You might have to adjust some things such as the inline styling (ie display).

    Please let me know if you have any questions.

    Thanks.

  5. 5 Posted by matthew.norton on 11 Sep, 2012 05:53 PM

    matthew.norton's Avatar

    This is working great Ryan. Velocity is so similar to PHP and yet handles some things differently. Could you recommend any online Velocity sites/documentation other then: http://velocity.apache.org/

    I find that there is limited resources online about the language.

    Thanks again!

  6. 6 Posted by Ryan Griffith on 11 Sep, 2012 06:11 PM

    Ryan Griffith's Avatar

    Glad to hear that Velocity is helping out. It didn't look the most elegant but seemed to do the trick.

    On thing I noticed in your original Format that you may run into in the future is that Velocity will complain if you open up an HTML tag and close it dynamically within a conditional later in your code (something that could be done in PHP). Take a look at lines 80 and 82 in your original Format for an example.

    Aside from the Apache Velocity website, we have some information on our knowledgebase that covers some of the tools and helpers that are available within Cascade. There also are some links to additional information on various objects in Java such as Dates and Strings.

    You could also check out these two repositories on our Github for some various examples:

    Please let me know if you have any questions.

    Thanks!

  7. Ryan Griffith closed this discussion on 18 Oct, 2012 07:18 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