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.

basic templates / url question

December 01, 2007 4:14pm

Subscribe [0]
  • #1 / Dec 01, 2007 4:14pm

    stef25

    268 posts

    after reading about templates and url’s ive kept this one liner in mind: to show the “index” template of the “weblog” template group, use: domain.com/weblog/index

    i have a site that has articles about religion, books and culture. i would like the url to be: domain.com/articles/religion, domain.com/articles/books and domain.com/articles/culture

    the layout of these pages will be identical: an h1 title that says books or culture or religion, with 10 divs below each showing excerpts belonging to those topics

    does this mean i need to create 3 identical templates named “culture”, “books” and “religion”? from a maintenance perspective this isnt a very logical thing to do.

    thoughts?

  • #2 / Dec 01, 2007 6:11pm

    GhostMeat

    2 posts

    You know, I’m a noob too and I’m 40% through building a site and I’m sort of asking myself this question too.

    So what I’m doing is that (I’m simplifying here) I’m basically making the header and footer of the website separate templates.  I put them in a template group named, say, “build”.  Then I create the actual site in another template group (called “content” for example) and for each template in that “content” group, I’m referencing the header and footer in the “build” template group. 

    So each page (to average website visitors, for gawdsake, it’s a “page”) of my site has three things:
    1. a template that represents each page.  it only includes content.
    2. a few lines in that particular page that pull in the header and footer templates in the “build” group.
    3. a weblog for each page that, of course, pulls in the content.

    This way, global website changes (like changing the main navigation, background color, etc.), can be made to the templates in my “build” group and I don’t have to change each and every frickin’ content page.

    Yep. Noobish!


    gm.

     

    after reading about templates and url’s ive kept this one liner in mind: to show the “index” template of the “weblog” template group, use: domain.com/weblog/index

    i have a site that has articles about religion, books and culture. i would like the url to be: domain.com/articles/religion, domain.com/articles/books and domain.com/articles/culture

    the layout of these pages will be identical: an h1 title that says books or culture or religion, with 10 divs below each showing excerpts belonging to those topics

    does this mean i need to create 3 identical templates named “culture”, “books” and “religion”? from a maintenance perspective this isnt a very logical thing to do.

    thoughts?

  • #3 / Dec 01, 2007 7:20pm

    PXLated

    1800 posts

    First, I’m presuming you have removed the index.php form your URLs as you don’t show it.
    Secondly, you don’t mention how you have your content set up. Content (data) and templates (presentation) are two separate things.
    —————
    There’s several ways you can achieve the URL you want but we’ll probably need to know how your content is structured…are the three areas separate weblogs or categories of one weblog, etc.

  • #4 / Dec 01, 2007 9:43pm

    allgood2

    427 posts

    Well assuming that you have removed index.php, as opposed to renaming it (articles), then I’ll assume your template_group is articles.  Like PXLated stated, part of this is dependent on how you set-up your data. But assuming—culture, books, religion, etc. are categories of a single weblog, then you turn on ‘using category_names’ instead of category_id for the url. 

    Basically, if you have a template_group (articles), with a template (index), then specify a category, the url would look like this http://www.mysite.org/articles/C125/  with C125 == Category 125 == Religion.  If you turn on using category names, then the url would look like http://www.mysite.org/articles/religion/.  There are some considerations though (1) using category names, requires a trigger, and I’m not certain if ‘articles’ could be your trigger. So you’d have to investigate.

    You could use multiple templates. This is actually easier to manage than you imagine. The trick is to have each template pull an embedded template.  This option will work for categories or separate weblogs.  The structure would be like: template_group == articles.  Templates are culture, books, religion, etc.  The template code is

    {embed="include/article"}

    In your second template_group include, you have the required EE code for separating content.  For example, if each of the areas were separate weblogs, you could have the code

    {exp:weblog:entries weblog="{segment_2}" orderby="date" sort="desc" limit="15"}
    
    <a href="/">{title}</a>. {summary} (<i>entry_date format='%F %d, %Y '}</i>
    
    {/exp:weblog:entries}

    Similarly, if the areas are categories, you could actually, use the embeds to just pass on the category_ids to the embedded template, the code would look something like this for the primary template (i.e. culture, religion)

    {embed="include/article_select" the_id="25"}

    where, the_id, is equal to the category_id you wish to display.  Then the embedded template would use code like

    {exp:weblog:entries weblog="weblog" category_id="{embed:the_id}" orderby="date" sort="desc" limit="15"}
    
    <a href="/">{title}</a>. {summary} (<i>entry_date format='%F %d, %Y '}</i>
    
    {/exp:weblog:entries}

    Obviously, you’d have to play around a bit, and some options are limited by how you structure your data, but EE is very flexible.

  • #5 / Dec 02, 2007 5:56pm

    stef25

    268 posts

    @allgood2: thanks alot for this in depth explanation!

  • #6 / Dec 02, 2007 6:23pm

    PXLated

    1800 posts

    stef25…curious to which way you have yours set up?

  • #7 / Dec 03, 2007 1:26am

    mayest

    293 posts

    stef25,

    allgood2 pretty much (I think) describes the technique that I found for my site a few days ago, except that I’m not using categories (yet).

    I have all of the parts of my “pages” chunked (thanks Mike Boyink, I got that great idea from your tutorial). Everything is in one template group: The html head tag, page header, page footer, CSS, etc are all in separate templates. They are pulled into one main template called “template_code” using embed tags like:

    {embed="{my_template_group}/.site_header” tg=”{my_template_group}”}

    and then it has the HTML coding - a bunch of divs and calls to EE tags.

    Now, the template_code template isn’t functional by itself and isn’t ever displayed directly. Instead, I have another template for each weblog that embeds the template_code template and passes the name of the weblog to it. So, if I had your site I would have three weblogs: religion, books, and culture and three templates with the same names. These are all identical, except for the name of the weblog that they represent. Here would be the code for the “religion” weblog:

    {assign_variable:my_weblog="religion"} {!-- Change this to the correct weblog name --}
    
    {assign_variable:my_template_group="site"}
    {assign_variable:my_stylesheet="css_styles"}
    
    {embed="{my_template_group}/template_code" wb="{my_weblog}"}

    The “books” and “culture” templates would be identical, except for the string assigned to my_weblog.

    Finally, the weblog:entries tag in the template_code template looks like this:

    {exp:weblog:entries weblog="{embed:wb}” limit = “1” disable=“member_data|trackbacks” sort=“asc”}

    Now, I only have one template that I need change if I want to rearrange the page layout (template_code) and all of my weblogs will always look the same. Also, if you hide index.php then you should get URLs that look like this:

    http://www.yoursite.com/site/religion

    or

    http://www.yoursite.com/site/religion/religion_page_2

    It seems to work for me, but I’m open to any critiques. Just don’t be too hard on me, I’ve only been doing EE for a couple of weeks.

    Tim

  • #8 / Dec 08, 2007 11:02am

    stef25

    268 posts

    sorry for the late reply. i was trying to figure out how to set things up. here is what i have, based on what allgood2 suggested

    the template called “article-select” in the “includes” template group:

    {exp:weblog:entries weblog="articles" category_id="{embed:cat_id}" orderby="date" sort="desc" limit="15"}
    <div>
    <a href="/">{title}</a>.  (<i>{entry_date format='%F %d, %Y '}</i>)
    {summary}
    {embed:cat_id}
    </div>
    {/exp:weblog:entries}

    the “travel-books” template. travel-books has an id of 220. i left out the doctype and html & head tags.

    <body>
    
    {embed="includes/header"}
    <h1>Travel Books template</h1>
    {embed="includes/article-select" cat_id="220"} 
    
    </body>

    so, i created three test postings in the Articles weblog. two are linked to the Travel Books category and one is linked to the Religion category.

    notice in the first bit of code i echo the cat_id, just to make sure the value is being passed. when i visit domain.com/index.php/articles/travel-books/ i see the all three postings, also the one in the religion category - this shouldnt be the case. below this Religion article is also shows “220” as an id, while the id for religion is actually 219.

    Similarly, when i visit domain.com/index.php/articles/religion/ i also see all three postings but the id is echoed as 219 - the correct id for religion, but the correct postings are not showing

    what am i doing wrong?

  • #9 / Dec 08, 2007 11:12am

    stef25

    268 posts

    i found that at the link below, the correct parameter for category id is actually “category” and not “category_id” as is seen in allgood2’s code. if i drop the “_id” part, nothing shows ... ? so should it be category_id after all?


    http://expressionengine.com/docs/modules/weblog/parameters.html#par_category

  • #10 / Dec 08, 2007 4:43pm

    allgood2

    427 posts

    Hi stef25, you are correct the parameter is category NOT category_id. I typed without referring to the manual or my old templates (bad girl).  I would ask, since you’ve added a check to see if the embed code is being brought over, is it?  I’d also say, you probably want the check {embed:cat_id} before the {exp:weblog} tag.  In fact, for troubleshooting purpose you may want:

    <b>category</b>: {embed:cat_id} 
    
    <ol>{exp:weblog:entries weblog="articles" category="{embed:cat_id}" orderby="date" sort="desc" limit="15"}
    
    <li><a href="/">{title}</a>.  (<i>{categories}{category_id}{/categories}</i>)</li>
    
    {/exp:weblog:entries}</ol>

    What the above code should do is:
    (1) provide you a count of pulled articles,
    (2) display the embedded cat_id, so you can tell what data is being passed to the {exp:weblog:entries} tag;
    (3) list the category or categories associated with the title of the displayed articles so you may compare it to the category_id being displayed by the embedded tag

    This will hopefully allow you to spot any immediate errors. For example if the embed isn’t being passed, then

    <b>category</b>: "{embed:cat_id}" 

      will display as category:  .

    If the embed code does echo correctly, then you can rapidly compare the embed cat_id against the articles category_id

    I know it took me awhile to get the embeds working properly, at least 2 or 3 tries, before I properly referenced the tags correctly on both ends. Compare the code against the manual.

  • #11 / Dec 09, 2007 9:29am

    stef25

    268 posts

    @allgood2 - working perfectly now, thanks!

  • #12 / Dec 09, 2007 11:31am

    allgood2

    427 posts

    Great!

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

ExpressionEngine News!

#eecms, #events, #releases