strandoo Posted September 18, 2019 Share Posted September 18, 2019 Hello ProcessPeople. I'm trying to get an xml file for a store locator-type map page. It works fine, but the client wants the icon colour to change depending on the location categories (which can be multiple categories). I've decide the easiest way to do this based on my existing javascript would be to just get multiple results in my xml file for those locations with multiple categories and let the js display. Like so: 'Location A' has 2 categories 'Residential, Health' 'Location B' has 2 categories 'Health, Education' 'Location C has 1 category 'Residential' I'd like a selector which would produce this xml (sort of like the opposite of 'unique'): <marker title="Location A" category="Residential" ... /> <marker title="Location A" category="Health" ... /> <marker title="Location B" category="Health" ... /> <marker title="Location B" category="Education" ... /> <marker title="Location C" category="Residential" ... /> Note that it doesn't matter if the result is 'category="Residential, Health"', as long as any location with 2 or more categories appears as a duplicate; I don't need to strip out the other categories since I'm using the first word of the category string to determine the colour of the marker. I think I may need only one category returned, if possible. There are only 5 categories in total. Any suggestions? I've tried searching through the forums and cheatsheet, but I don't really know the term for what I'm looking for. Non-unique? Thanks. Link to comment Share on other sites More sharing options...
Robin S Posted September 19, 2019 Share Posted September 19, 2019 Assuming the categories are assigned to locations by a Page Reference field named "categories": $locations = $pages->find("template=location"); foreach($locations as $location) { foreach($location->categories as $category) { echo "<marker title='$location->title' category='$category->title'/>"; } } 2 Link to comment Share on other sites More sharing options...
strandoo Posted September 19, 2019 Author Share Posted September 19, 2019 @Robin S Thanks, that's perfect. I can't believe it was that simple; I was definitely over-thinking it, trying things like append and add. Many thanks. - P 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now