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.

Assigning a Template Group based on Category

August 23, 2007 12:06am

Subscribe [3]
  • #1 / Aug 23, 2007 12:06am

    michaelTSCPL

    105 posts

    Can I assign a template group based on a category in a post?  Something like:

    {exp:weblog:entries orderby="date" sort="desc" category="not 45|57|58|59|60|61|62|63" limit="5"}
    
    {if category=="21|22|23|24|25|26|31|32|33|34|35|36|37|38|39"}
    {assign_variable:my_template_group="research"}
    {if:elseif category=="30|52"}
    {assign_variable:my_template_group="programs"}
    {if:elseif category=="55|56"}
    {assign_variable:my_template_group="services"}
    {if:else category=="36"}
    {assign_variable:my_template_group="movies"}
    {/if}
    
    <a href="http://{title_permalink={my_template_group}/comments}">{title}</a>
    {body}
    {

    The above code does not work and actually results in a blank page generated.

  • #2 / Aug 23, 2007 12:11am

    Derek Jones

    7561 posts

    No, I’m afraid that will not work, Michael.  Please read the “note” box in the user guide regarding the Assign Variable tag.  You could, however, use custom statuses, category custom fields, or PHP on output.

  • #3 / Aug 23, 2007 12:12am

    Lisa Wess

    20502 posts

    Perhaps you can tell us a bit more about your end goal?  I ask because templates pull data out, they are not intrinsically linked to any of your weblog data, so having a template that belongs to a category isn’t quite the right approach. It’s more like “what data am I displaying via this template?”

  • #4 / Aug 23, 2007 8:17am

    michaelTSCPL

    105 posts

    Actually what I am trying to do is have the template belong to the weblog…

    My end goal is this…I have a recently added section on the home page that is displaying all of the updated weblogs. When they select the title or read full entry link I want it to go to a specific template based on the weblog that it is associated with.

    I am sure that I am missing something simple here.

  • #5 / Aug 23, 2007 10:51am

    Robin Sowell

    13255 posts

    A lot of ways to go at it- and if you don’t really need to, I wouldn’t make a separate template group for each weblog.  Because I am lazy, and the fewer templates I use the happier I am when I have to change stuff up. 

    That said?  Probably the easiest thing to do is use a link to a single entry page that is weblog specific- for example the {comment_url_title_auto_path} variable- it uses the comment path specified on a per weblog basis in ‘Admin- Weblog Admin- Weblog Management’- for each weblog, you can specify a comment, weblog, and search path.

    I’ve also been known to give the weblogs a shortname that matches a template- or template group- for doing similar stuff.  Though usually I’ll send all of the weblogs through the same template- but maybe pass the shortname as a segment, so only the entries in THAT weblog get shown.  Could use it for specifying a template as well.

    But yep- lots of ways to go about it.  For what you need, I’d go with the comment url title type thing.

  • #6 / Aug 23, 2007 11:20pm

    michaelTSCPL

    105 posts

    I will definitely try to give some of these a try. Unfortunately because of the design that I am using with tabs I need to find out a way to make this work. Thanks so much for the help.

  • #7 / Aug 24, 2007 1:36am

    stinhambo

    1268 posts

    A lot of ways to go at it- and if you don’t really need to, I wouldn’t make a separate template group for each weblog.  Because I am lazy, and the fewer templates I use the happier I am when I have to change stuff up.

    Am I right in thinking that this doesn’t apply if each weblog uses a different custom field group?

  • #8 / Aug 24, 2007 2:25am

    Lisa Wess

    20502 posts

    That depends, stinhambo - you have to call those custom fields, but if they have no content they’ll just be ignored. If you need to label then you might need some conditionals -but you can still call them all in one template.

  • #9 / Aug 24, 2007 2:30am

    stinhambo

    1268 posts

    Mmm yes thats true. I did consider this for my current project but I wanted to use the template group segment and category name to activate navigation highlighting. Plus I have 10 category fields per weblog and 12 weblogs. Gets a bit long!

    It would be great if there was a service (or bribe) to get an expert to look over a project and say where it can be streamlined. I’d learn a shed load that way! For all I know I could be creating sites in a shorter time and be more efficient or more extendable…

  • #10 / Aug 24, 2007 2:33am

    Lisa Wess

    20502 posts

    I’m sure that there are folks on the Pro Network that might be willing to do an infrastructure review with you…

  • #11 / Aug 24, 2007 8:47am

    michaelTSCPL

    105 posts

    I wanted to pass on that Robins suggestion of the {comment_url_title_auto_path} variable did the trick for what I needed.  Thanks so much for helping me with this.

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

ExpressionEngine News!

#eecms, #events, #releases