ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to avoid the need for unique URL titles?—or—What the EE way is to do what I’m trying to do?

September 21, 2011 5:24pm

Subscribe [3]
  • #1 / Sep 21, 2011 5:24pm

    Waldo Jaquith

    30 posts

    I’m in the midst of a multi-month process of moving an existing site into ExpressionEngine. There’s a use pattern that I keep encountering (and putting off figuring out how to employ) that probably indicates that I’m not doing things the ExpressionEngine way.

    Our site contains essays about every president. For all 43 of them we’ve got “A Life in Brief,” “Domestic Affairs,” “Foreign Affairs,” “Impact and Legacy,” etc. Ten in all. And we have an appropriate URL structure. example.com/president/ is a listing of the presidents, example.com/president/washington/ is a listing of essays about George Washington, and example.com/president/washington/life-in-brief/ is the “Life in Brief” essay about Washington.

    The trick is porting this to EE. I’ve established a channel called “Essays.” Each essay has a channel field called “Essay Type,” a select field where one can pick from any of the available essay types. And each essay has a channel field called “President,” a relationship field where one can pick from the presidents. Those two elements are, at least logically, all of the information that needs to be stored to be able to retrieve these essays via that URL and ensure that they are unique.

    The problem here is the URL Title field, which EE requires be unique per channel. Obviously, I don’t want a redundant URL like /president/washington/washington-life-in-brief/. I just want /president/washington/life-in-brief/. I’d hate to have to use the Pages module to manually specify a URL for every one of these essays.

    Rather than ask about how to work around the requirement that URL Titles be unique within each channel, I get the sense that I’m doing something wrong here—that I’m thinking of this problem in an un-EE way. Should I be using “Categories” for this? Would that make any difference? Am I doing this all wrong? Or is this URL structure simply not how EE does things?

    I can surely work around all of this with mod_rewrite, but it’d be nice to have EE producing pages at the paths where I actually intend to use them, with URL slugs that I really intend to use, etc. I’d be grateful for any guidance about what I’m doing wrong.

  • #2 / Sep 22, 2011 9:18am

    Sue Crocker

    26054 posts

    Hi, Waldo.

    You’ll need to have unique url_titles, that’s going to still be needed. However, you can use the Pages module to have the urls you prefer. It’s simply how EE does things.

  • #3 / Sep 22, 2011 10:33am

    Waldo Jaquith

    30 posts

    Huh. OK. The EE way of doing things turns out to be rather more basic than I thought. Well, thanks for that, Sue.

  • #4 / Sep 22, 2011 6:57pm

    Kevin Smith

    4784 posts

    Hi Waldo,

    It looks like you’re certainly shooting for a URI structure that isn’t quite what EE produces by default, but there might be a way to do this without mod_rewrite.

    Let’s examine your URI:

    /president/washington/life-in-brief/

    Segment 1: president
    Segment 2: washington
    Segment 3: life-in-brief

    Based on a normal EE setup, your first segment (‘president’) is the template group. I’m assuming the second segment will contain each president’s name, so that means your template in this case is just “index”, and we’re ignoring it in the URI. So the second segment (‘washington’) will denote the President whose information should be on screen with the page load.

    Now, with your setup, the third segment can be something like ‘life-in-brief’ for every president and in your index template you can test for the presence of ‘life-in-brief’ in the third segment. If it’s there, display one particular embed (perhaps one called ‘president/life-in-brief’). If not, display this other embed (perhaps one called ‘main’).

    And then in the ‘president/life-in-brief’ template, you can accept an embed variable from the parent template that will let ‘president/life-in-brief’ know which president’s “life in brief” entry to display.

    Does that sort of setup make sense? That way, it doesn’t matter what the URL title of each president’s “life in brief” entry is, you’re manually determining which ones to show. (And don’t forget to use the dynamic parameter where necessary!)

  • #5 / Sep 23, 2011 3:48pm

    Waldo Jaquith

    30 posts

    I feel a lot better about ExpressionEngine after reading your response, Kevin. Maybe it’s just the crusty old Perl programmer in me, but I don’t trust any framework that has only one method of accomplishing something. 😉 I haven’t tried out any portion of your suggestions yet, but it all makes logical sense. More important, I’m now aware of EE functionality that I wasn’t previously aware of, and I know how to string it together in a way that I hadn’t realized was possible.

    Thanks so much, Kevin.

  • #6 / Sep 27, 2011 1:47am

    John Henry Donovan

    12339 posts

    Glad that helps Waldo. I’m actually going to move this thread to the Community help forum for you so as to keep it open and give you time to try a few things.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases