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.

Using 1 template as a single entry AND multiple entry page

October 23, 2007 12:10am

Subscribe [1]
  • #1 / Oct 23, 2007 12:10am

    Michael Layne

    26 posts

    Is there a way to use 1 template (template_group/index) to view a listing of entries AND single entry details based on URL segments?  Actually, I figured out how to do that with some simple conditions.  Worked beautifully until I had enough entries to have to use the pagination.  Yep, it sort of blew up in that “/P10/” is not /my_new_article/ and things broke.  I see from browsing around EE sites (like http://veerle.duoh.com/) that there is usually some other template like ‘entry’ or ‘comments’ that is the place to display an actual entry.

    I didn’t really know any better and I came pretty close to having it all work great.  Am I missing something or am I just wrong?

    initial development:
    http://brussels/ee/articles/ - was a complete listing
    http://brussels/ee/articles/my_article/ - was just the one article complete with dynamic title, etc.

    after pagination issue:
    http://brussels/ee/articles/
    http://brussels/ee/articles/read/my_article/

    Is that what I need to do?  Sorry for the long post… I’ve been developing a site for a client for the past 2 months and have 100 templates so far. A bit daunting but I am so impressed with EE… Thanks.

  • #2 / Oct 23, 2007 12:12am

    Lisa Wess

    20502 posts

    Hi, Michael - have you read The Importance of Semantics series?  You can find it here - I’d read from Page 2 backwards, there are 4 articles in total and they’re not very long.  It explains how this all works. =)

    You probably should not need 100 templates (I only say probably because I am not familiar with your project) - but it is hard to say without more details about your project.  Read through those articles and see if it helps. =)

  • #3 / Oct 23, 2007 1:25am

    Michael Layne

    26 posts

    Thanks, Lisa.  I’ll read through them and hopefully get it. You may be right about the number of templates, but the client is very specific about URL structures and they have thousands of blog posts and articles by categorized by “communities”, which we now have as categories within EE. I can point you to the dev site if it would help you help me.  Just an opinion… I’m not looking for you to do any work! 😊

    BTW - The way I had it almost working was by looking for the existence of a URL segment. Then some conditional statements. I’ll jump back here if I can ask a specific question and need to.

    Thanks again for all your help!

  • #4 / Oct 23, 2007 1:27am

    Lisa Wess

    20502 posts

    Sure, PM the link; I’ll try to have a look at it tomorrow - I’m mostly just curious why you’d need that many templates.  I hope you’re at least making good use of embeds and the other variable options!

  • #5 / Oct 23, 2007 10:31am

    Robin Sowell

    13255 posts

    Heh- Lisa’s right.  It just varies a lot.  I’m using this in a similar situation- avoids the pageination pages blowing up issue- php turned ‘on’:

    <?php
    global $IN;
    $qstring = $IN->QSTR;
    $seg2 = '{segment_2}';
    if (preg_match("#(^|\/)P(\d+)#", $qstring, $match) OR $seg2 == '') { ?> 
    
    {embed="opinion/multi"} 
    
    <?php } else { ?> {embed="opinion/single"} <?php } ?>

    That’s on the index page.  Get a multi-page template embeded if there’s no seg2 or if it indicates that it’s a page number- otherwise, we flip in a single page setup.

    But- lot of ways to approach it.

  • #6 / Oct 23, 2007 11:11am

    Daniel Walton

    553 posts

    Sorry to step in, but to note; using ereg(), rather than preg_match(), would be the preferred method since you have no use for any matches, just a true or false return 😊

  • #7 / Oct 23, 2007 11:16am

    Robin Sowell

    13255 posts

    Heh- in truth I ripped it off from some other code w/out thinking about it.  Good call, the_butcher.

    (I’m going to have to ask you about that handle some time 😉 )

  • #8 / Oct 23, 2007 12:34pm

    Michael Layne

    26 posts

    Thanks for the help and feedback.  I hear you all and I’m learning… so let me ask this question:

    Why do I so often see:
    domain.com/blog/
    (multi-page, right?)

    then

    domain.com/blog/entry/my_blog_entry_title/

    I get that there must be more than one way of doing things, but as Robin pointed out, my issue seemed to be with the pagination (P(\d+)). BTW - that bit of logic wasn’t in the first page of the documentation =) I’m sure I’ll end up trying/using it.

    Due to the time factor, I had to go the “single-entry” template route for the sake of keeping the project and the client on track. I simply could not resolve the multi-purpose template and the pagination.  GREAT forum.  Thanks.

  • #9 / Oct 23, 2007 1:10pm

    Robin Sowell

    13255 posts

    Oh- the php bits are almost never in the official docs- because you really shouldn’t, and don’t, need to know php to use EE effectively.  But if you know a bit, it expands things greatly.

    As to why folks do it blog/entry/title- it’s just easier if you aren’t anal about urls (or wanting to dork around with it- I think Rick had his whole site running off of one template).  I personally prefer one template for multi-entries- and send all weblogs to that one template- and one template for all single entries- likewise handling all weblogs.  But in the above example, we were shooting for mirroring an existing structure- wanting urls for the individual weblogs to be mysite/weblog_name and single entries mysite/weblog_name/entry_title- so I went with a template group for each weblog- and in that group, a template for the multi-entries and another for the single entries.  More templates, thus more setup time, thus more maintainence time.  Which is why it’s good to charge by the hour 😉.  Just know what the key goals are at the start- if the url structure is critical, it’s going to influence how you set things up.

  • #10 / Oct 23, 2007 1:29pm

    Michael Layne

    26 posts

    Just know what the key goals are at the start- if the url structure is critical, it’s going to influence how you set things up.

    You can say that again.  I guess I’ll get it right (or at least know my options) on the next project. I would be a one template guy I think…

    BTW - I was kidding about the PHP code being in the documentation =) Thanks again!

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

ExpressionEngine News!

#eecms, #events, #releases