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.

Multiple weblog entries and templates

August 13, 2007 12:34am

Subscribe [3]
  • #1 / Aug 13, 2007 12:34am

    Kenn Christ

    26 posts

    Just when I thought I had gotten my head around EE URLs, templates, and weblogs, I ran into a new problem that’s left me a little puzzled.

    I’m putting together a site with a few weblogs and a few template groups. I’m using a weblog->template group naming association to keep things organized for myself and so my site URLs make sense. The front page of the site will display content from all the weblogs, in a single blog-style reverse chronological format. This part works fine.

    Where I’m running into trouble is with my review section. I’m writing reviews for books, music, etc, and had envisioned a URL structure like this:

    <a href="http://www.example.org/reviews/music/">http://www.example.org/reviews/music/</a>
    <a href="http://www.example.org/reviews/books/">http://www.example.org/reviews/books/</a>

    After reading all about how EE uses URLs and templates, I created a “reviews” template group and templates named “music” and “books”, thinking this would take care of it. The problem I’ve run into now is that I don’t know how to tell EE to use the appropriate template when generating links on the front page. All the entries appearing on the front page want to use the “main” template group that my main index template lives in. I’m able to specify the correct template groups by writing links like this in my index template:

    <a href="/{weblog_short_name}/{url_title}">{title}</a>

    This is where you see how sharing a name between weblogs and template groups keeps URLs logical. The problem is that all URLs use the index template in the specified template group. This works fine for most of the site, but means I can’t use URLs like the above for the book and music reviews. Hard-coding the template in the URL works but I can’t do this because this code is displaying content from multiple weblogs, not just the reviews.

    I think I could do something by creating categories named music, books, etc, and checking for them when constructing the links, but this seems convoluted and unnecessarily complex, especially given that posts may be in multiple categories.

    I feel like just when I thought I had figured out template groups and page templates I realize that it doesn’t actually work the way I thought.

    The funny part is that I’m porting over a site that currently uses URLs like the above but without “reviews” in the path. I added that after figuring out that EE requires template groups in URLs and deciding that creating separate groups for books, music, etc, is somehow fundamentally missing the point.

    So help me out. Is there a simple way to do this that I’m missing? How are these page templates normally used if there’s no easy way to automatically generate permalinks using them?

  • #2 / Aug 13, 2007 5:22am

    Phoebe

    58 posts

    Probably missing the point entirely, but can’t you just hard code the links?

    <h2>Book Reviews</h2>
    <p>{exp:weblog:entries weblog="books" ....</p>
    
    <p><a path="reviews/books/{url_title}">{title}</a></p>
    
    <p>{/exp:weblog:entries}

  • #3 / Aug 13, 2007 8:46am

    Mark Huot

    587 posts

    or even:

    <a href="http://{url_title_path=reviews/books}" title="Read more “{title}”">{title}</a>

    http://expressionengine.com/docs/...

  • #4 / Aug 13, 2007 10:40am

    Kenn Christ

    26 posts

    No, I can’t hard code them because the front page is displaying content from multiple weblogs, not just reviews, all coming from a single weblogs:entries loop and therefore using the same display code.

  • #5 / Aug 13, 2007 10:54am

    Mark Huot

    587 posts

    this may work then:

    <a href="http://{url_title_path=reviews/{weblog_short_name}}" title="Read more “{title}”">{title}</a>
  • #6 / Aug 13, 2007 12:31pm

    Lisa Wess

    20502 posts

  • #7 / Aug 13, 2007 2:00pm

    Kenn Christ

    26 posts

    I tried {comment_url_title_auto_path} too. This has the same problem as hard coding the template: the reviews weblog contains different types of reviews, so I can’t hard code /reviews/books into the comment URL setting because this will affect music reviews as well.

    As far as I can tell, what I want to do isn’t really possible, which is disappointing. My options at this point seem to be to a) just use /reviews/ for all the reviews, regardless of type, or b) create separate weblogs for each review type. Neither are ideal, but the first option is much better than the second. I think losing a little semantic information in the URL is preferable to having to manage separate weblogs for each different type of review, which I suspect can quickly get unmanageable.

  • #8 / Aug 13, 2007 2:01pm

    Lisa Wess

    20502 posts

    How are these reviews set apart, kchrist?  What differentiates them in the actual entries?

    You could use categories, statuses, a custom field, and use conditionals to send them to the correct template, but you’ll need something in the entry that sets it apart.

  • #9 / Aug 13, 2007 3:45pm

    Kenn Christ

    26 posts

    I’m using categories of “books”, “music”, and so on within the Reviews weblog. It occurred to me to check the category and set a variable with the appropriate template/URL before displaying each post but then I discovered that I can’t set variables within conditionals. Because I’m using the single-entry URL in two places in each post on the front page—the post title and a “Continue reading…” link—I think checking categories to construct links will require looping through the categories twice, once in each of these places. Is this right, or is there a better way to do this?

    Thanks for your help.

  • #10 / Aug 13, 2007 3:48pm

    Lisa Wess

    20502 posts

    You are correct that you would need to loop through the categories tag twice for that. You could use a custom field with “template type” and use that for conditional links…

  • #11 / Aug 14, 2007 11:59am

    Kenn Christ

    26 posts

    I’ve decided to just check the category twice, once for each link I’m constructing. The following is what I ended up with, which works fine:

    {categories}
    {if ((category_url_title == "books") || (category_url_title == "music"))}
    <h2><a href="/{weblog_short_name}/{category_url_title}/{url_title}">{title}</a></h2>
    <p>{if:else}</p><h2><a href="/{weblog_short_name}/{url_title}">{title}</a></h2>
    <p>{/if}<br />
    {/categories}

    I encountered a new problem here in that I had a conditional inside this H2 element that checked {count} and applied a CSS style to the first post on the page. This apparently breaks the {categories} loop; the categories tags aren’t parsed if this check is present and the raw EE code is returned to the browser.

    <h2{if (count == 1)} class="first"{/if}><a href="/{weblog_short_name}/{url_title}">{title}</a></h2>

    The {count} variable works as expected; I tested that I can print the count number with each post. It’s only when it’s enclosed in a conditional (which is, in turn, enclosed within the {categories} pair) that it breaks. This is odd because the conditional that checks the category works, so it’s obviously not just a problem with {if} statements inside {categories} pairs.

    I don’t know if this is a bug or if there’s an explanation, but thought I’d mention it. It’s not real important to me so I’m just going to live without it.

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

ExpressionEngine News!

#eecms, #events, #releases