matching system-page/title to page variable to pull data from index block
We have a content index block that indexes all of our locations.
On our individual service line pages, we'd like to use that index block to pull in the links to the locations those services are available at.
I believe the issue with my format is the way I'm setting the $locs variable - specifically, how I'm referencing the title.
#set ( $locs = $_XPathTool.selectSingleNode($contentRoot,
"/system-index-block/system-page[('title') and
value='${locMatch}']") )
I've also tried:
#set ( $locs = $_XPathTool.selectNodes($contentRoot,
"/system-index-block/system-page[('title') and
value='${locMatch}']") )
We have a similar format that uses our dynamic metadata to match
providers to a location/service line and those are working. This is
the way we are setting the $loc variable on those pages:
#set ( $locs = $_XPathTool.selectNodes($contentRoot,
"/system-index-block/system-page[dynamic-metadata[(name='primary-location'
or name='secondary-location') and value='${locMatch}']]")
)
I've attached the full format and a sample of our index block xml.
Thanks in advance for the help.
- location-specialty.txt 2.69 KB
- location-index-sample.txt 9.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 08 Jun, 2015 01:25 PM
Hi Lauren,
You have the right idea here, but the XPath syntax to filter by value for a static metadata field is slightly different than that of a dynamic metadata field.
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!
2 Posted by lauren.fraser on 08 Jun, 2015 03:11 PM
Ryan,
I'm still not getting any results. I added a line to escape the $locMatch variable just to make sure I had that correct, but I'm still not getting any results with my $locs "match."
Thanks,
Lauren
3 Posted by Ryan Griffith on 08 Jun, 2015 07:47 PM
Hi Lauren,
I just noticed you are most likely trying to return multiple locations, but you are using
selectSingleNode
. Have you tried the following by chance?Please let me know if you have any questions.
Thanks!
4 Posted by lauren.fraser on 08 Jun, 2015 08:11 PM
That got it. I’d tried SelectNodes before – but I wasn’t calling the title correctly.
5 Posted by Ryan Griffith on 08 Jun, 2015 08:25 PM
Thank you for following up, Lauren. 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 08 Jun, 2015 08:25 PM.
lauren.fraser re-opened this discussion on 24 Jun, 2015 08:57 PM
6 Posted by lauren.fraser on 24 Jun, 2015 09:05 PM
Ryan,
I'm trying to get the page to pull multiple locations.
In our data definition, I set the location-match field to allow multiples and entered a second location on a test page. This is the xml
I'm not seeing the second location on our page. This is how I've set the $locs variable:I'm assuming I need to change something with my
$locs
variable. Possibly adding in a#foreach
statement, since the$locMatch
variable has multiple entries/values, that need to be matched with the correct data in the index block. (Instead of one$locMatch
value that is matched with multiple items in the index block).I'm guessing I could manually build out separate location match fields in our data definition (location-match2, location-match3), then check if those are empty and adjust the velocity as needed.
If there's a way though, I'd rather keep the single location-match field in our data definition and allow multiples, so the data definition and format don't need to be adjusted if we add a new location.
7 Posted by Ryan Griffith on 25 Jun, 2015 12:33 PM
Hi Lauren,
You are correct. The best way to accomplish this would be to loop over each
$locMatch
and build out an XPath statement to be used for your$locs
variable. You will also need to use thegetStructuredDataNodes
method since you are returning multiple fields instead of just one.I didn't have a chance to test this, but something like the following for starters:
Please let me know if you have any questions.
Thanks!
8 Posted by lauren.fraser on 25 Jun, 2015 02:21 PM
Ryan,
That worked great! A quick semi-related question. Further in my down in my velocity script I have the for each loop (#foreach $loc in $locs)the displays the location information. I added this code to the end of it:
#if ($locs.size() > 1)
<div class="divider-mobile"></div>
#end
It works exactly like I’d expect, adding the div tag in each instance. How can I check to for the last $loc and not output the divider-mobile div there?
Thanks,
Lauren
9 Posted by Ryan Griffith on 25 Jun, 2015 06:01 PM
Hi Lauren,
I believe the following should do the trick:
For additional information about the
$foreach
variable, feel free to check out this page on our Knowledge Base (under the Velocity 1.7 improvements section).Please let me know if you have any questions.
Thanks!
10 Posted by lauren.fraser on 26 Jun, 2015 07:30 PM
Ryan,
That worked great. Thanks!
11 Posted by Ryan Griffith on 26 Jun, 2015 08:29 PM
Not a problem at all, Lauren, I am glad to hear the proposed change 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 26 Jun, 2015 08:29 PM.
lauren.fraser re-opened this discussion on 10 Jul, 2015 04:17 PM
12 Posted by lauren.fraser on 10 Jul, 2015 04:20 PM
Ryan,
We've been asked to implement multiple locations on a page that matches the
location-match
field to dynamic metadata fields.I tried editing the code you provided, but I'm not getting something right in the way I'm defining the $locsXPath. I commented out the way it was defined when we were matching it to a system meta data field. Then tried using the XPath for when we were just matching on
location-match
field, but I'm not getting any results.Thanks in advance for your help.
13 Posted by Ryan Griffith on 13 Jul, 2015 12:43 PM
Hi Lauren,
To confirm, are you trying to match on the
primary-location
andsecondary-location
dynamic metadata fields instead oftitle
? If so, you would want something similar to the original code, but instead of title, you need to match on the value of the dynamic fields.When you have a moment, let's give the following a try and see how it works out:
Please let me know if you have any questions.
Thanks!
14 Posted by lauren.fraser on 13 Jul, 2015 04:49 PM
I got this:
Attached are sample xml from the index block, the page xml and the complete format.
15 Posted by lauren.fraser on 13 Jul, 2015 04:51 PM
Sorry, I posted the wrong Format. Attached is the updated version
16 Posted by Ryan Griffith on 13 Jul, 2015 06:30 PM
Hi Lauren,
My apologies, I forgot to uncomment the setting of
$locsXPath
in my code snippet based on your provided code. When you have a moment, please try the following:Please let me know if you have any questions.
Thanks!
Tim closed this discussion on 11 Aug, 2015 07:07 PM.