0

I have a very specific URL structure I'm trying to set up:

city-segment/venue-segment

ex. houston/the-bar

"city-segment" pulls from a City Channel while "venue-segment" pulls from a Venue Channel. I've got it set up correctly using the Pages Module, but now I'm trying to display a field from the City Channel using a third segment:

houston/the-bar/information

"information" segment should display text entered into the {venue_info} field of "The Bar" Venue Channel Entry. I have an info template within the venue template group with this code:

{exp:channel:entries
  channel="venues"
  disable="categories|member_data|pagination"
  dynamic="no"
  limit="1"
  require_entry="yes"
  status="open"
  url_title="{segment_2}"
}

  {venue_info}

{/exp:channel:entries}

Trying to view this code gives me nothing. I'm guessing that assigning a Channel Entry to a URI using the Pages Module is preventing me from using any segment variables? If so, is there another way to solve this without using Structure?

Venue/Info Template

{layout="_layouts/.html-layout"}

{layout:set name="city" value="{segment_1}"}

Hi

{exp:channel:entries
  channel="venues"
  disable="categories|member_data|pagination"
  limit="1"
  require_entry="yes"
  status="open"
  url_title="{segment_2}"
}

  {title} Info

{/exp:channel:entries}

3 Answers 3

2

You can do this using Resource Router instead of the Pages module. In your system/expressionengine/config/config.php file:

$config['resource_router'] = array(
    ':any/:any/(info|menu|hours|some_other_page)' => function($router, $wildcard1, $wildcard2, $wildcard3) {
        $validCity = $wildcard1->isValidUrlTitle(array('channel' => 'cities'));

        $validVenue = $wildcard2->isValidUrlTitle(array('channel' => 'venues'));

        if ($validCity && $validVenue)
        {
            $router->setTemplate('_venues/_'.$wildcard3);
        }
        else
        {
            $router->set404();
        }
    },
);

This example assumes you have a _venue template group with _info, _menu, _hours, and _some_other_page templates. In your templates can you just refer to {segment_X} variables as normal.

4
  • Thanks Rob! Should I use this solution for the city/venue and city segments as well? Instead of using the Pages Module as I'm doing now? Commented Jan 19, 2015 at 18:22
  • I'm using the Resource Router in config as outlined and it is working, but it's not rendering any variables between {exp:channel:entries} tags. See above for what I have for the venue/info template. It renders the layout:set for city and "Hi", but not the content within the entries tags. Commented Jan 19, 2015 at 18:34
  • You probably need to add dynamic="no" to your channel:entries tag. Commented Jan 19, 2015 at 20:36
  • Did the trick, thanks! Now, I'm trying to take it a step further by using Croxton's "Multi-language routing with Resource Router" example, but instead using a channel entry segment. This way I could always ensure there was a city URL title in the first segment, but it doesn't seem to be working: gist.github.com/tinchco/bced087af51f2dfec71e Commented Jan 19, 2015 at 20:42
1

It seems like an embed might help you get the job done.

Can you you do something like this:

{embed="_embeds/venue" segment_2="{segment_2}"}

Then in your embedded template:

{exp:channel:entries
  channel="venues"
  disable="categories|member_data|pagination"
  dynamic="no"
  limit="1"
  require_entry="yes"
  status="open"
  url_title="{embed:segment_2}"
}

  {venue_info}

{/exp:channel:entries}
0

Did you select the information template in the Pages tab?selecting template

Your code should work fine.

4
  • I can't since the content I want to display is within a field in the Venue Channel. It's not its own page. Commented Jan 19, 2015 at 8:22
  • Hmm, sounds like a good case for Template Routes - have you looked into that? ellislab.com/expressionengine/user-guide/urls/… Commented Jan 19, 2015 at 8:42
  • I was looking into this, but it looks like the first segment has to be a template group name. With my implementation the first segment will always be a city name and creating a template group for each city name is not scalable. Commented Jan 19, 2015 at 8:57
  • The first segment doesn't have to be a template group name. So you could have a route matching /{city}/{venue}/information and then you could use {segment:city} and {segment:venue} in your template. You would proably also need to apply this patch: support.ellislab.com/bugs/detail/20285 Commented Jan 20, 2015 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.