I'm trying to set up a site for clients that have locations in multiple cities and who want to be able to display something specific to that location on certain pages. I would like to set up routes using the city name as a variable, followed by the page (i.e. mysite.com/chicago/pricing, mysite.com/boston/pricing, etc.), and have it route to the same section and template with all of that section's corresponding entry fields.
I was planning to grab the URL parameter as a variable that enables me to dynamically load content based on a simple string match for that variable. I want to do something like this
{% set location = matches[1] %}
{% if not location %}
{% set selectedLocation = locations.defaultLocation %}
{% else %}
{% set selectedLocation = location %}
{% endif %}
....
{% for plan in entry.pricingPlans %}
{% if plan.location == selectedLocation %}
...
{% endif %}
{% endfor %}
I can route to the template itself just fine, but I don't get the data. Any suggestions on how best to achieve this? I'm not very PHP savvy and have only recently started getting to more advanced tasks in Craft.
{% set entry = craft.entries.section('pricing').first %}ifentrywas null, that way I can handle cases where a user goes tomysite.com/pricing(where the section is passing the entry data) ormysite.com/boston/pricing(where I need to pull fromcraft.entries.section). Thanks. – GMStevens Jun 01 '17 at 15:11