Determine if Link Exists (bread crumbing)
Hi All, I am working from of the sample code in the git repo specifically: https://github.com/hannonhill/Velocity-Cookbook/blob/master/Breadcr...
I am using this source to successfully generate breadcrumbs, but am attempting to add a check into the source to see if a page exists. The code in the git repo makes the assumption to fall back to the "index" or whatever you specify as your "index" which is helpful, however some of the folders may not have an "index" and I'd like to introduce a check to see if the index exists, if so, output the link as is, if not, output a non clickable link.
See line 51 on the Velocity script in the link above.
I tried to make a pageExists macro, but was un-successful, any help is appreciated. Thanks!
Brendon
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 05 Mar, 2014 07:16 PM
Hi Brendon,
Macros are meant to output and not necessarily return things like boolean values, there are ways to work around that, though.
I think your best bet would be to create a macro that takes in the folder element, checks to see if there is a corresponding landing page, and generates the link if one exists. You would call this macro in the two places where the link is currently displayed.
When you have a moment, perhaps give the attached Forma a try and let me know how it works out.
Please let me know if you have any questions.
Thanks!
2 Posted by birwin on 05 Mar, 2014 08:14 PM
Hi Ryan I really appreciate you taking the time to answer!
The breadcrumb code you wrote appears to output the region name as the last link (which is easy to fix, simply bydoing a #if( ${foreach.hasNext} and wrapping that in the loop) which could mean I likely did something wrong. I based my index breadcrumb block on: http://www.hannonhill.com/kb/Breadcrumbs/index.html
Thanks again!
3 Posted by Ryan Griffith on 05 Mar, 2014 09:29 PM
Not a problem at all, I am glad to hear the format helped out and you were able to work out that region name issue.
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 05 Mar, 2014 09:29 PM.