We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Dynamic Template Name in URL

How Do I?

lando's avatar
lando
5 posts
8 years ago
lando's avatar lando

Hi, I want to display a list of categories an entry is assigned to, and these categories should link back to their respective pages. Now those categories are attached to different templates so I need to display the template name dynamically for each category (hope it makes sense…)

I created this query:

{exp:query sql="SELECT template_name FROM exp_templates WHERE template_id = ‘{template_group}’”}{template_name}{/exp:query}

but unfortunately it still doesn’t display my template name.

To give you an idea, if I use this query:

{exp:query sql="SELECT group_name FROM exp_category_groups WHERE group_id = '{category_group}’”}{group_name}{/exp:query}

Then the group name shows correctly, but I don’t need the group name, I need the template name!

In case you want to see my code in action:

http://www.dev.ogaora.com/mcf/people/partner/david-byers

On the right below the thumbnail, the Practice Areas are the categories I want to link back to.

Any suggestions to point to the right direction?

Thanks in advance!

       
Rob Allen's avatar
Rob Allen
2,950 posts
8 years ago
Rob Allen's avatar Rob Allen

For the practice area categories what URL’s are you trying to create?

       
lando's avatar
lando
5 posts
8 years ago
lando's avatar lando
For the practice area categories what URL’s are you trying to create?

The categories are Finance, Corporate, Real Estate and Industry Sectors so the URL segments would be “finance”, “corporate”, “real-estate”, “industry-sectors”.

       
Rob Allen's avatar
Rob Allen
2,950 posts
8 years ago
Rob Allen's avatar Rob Allen

You could add a custom category field to hold the template name, then in your categories tag:

So to get the template name “corporate” create a custom category field called something like cat_template. Update your categories with the template name.

Then in your categories tag something like this:

{exp:channel:categories}
    <a href="/mcf/people/partner/{cat_template}/{category_url_title}">{category_name}</a>
{/exp:channel:categories}
       
lando's avatar
lando
5 posts
8 years ago
lando's avatar lando
You could add a custom category field to hold the template name, then in your categories tag: So to get the template name “corporate” create a custom category field called something like cat_template. Update your categories with the template name. Then in your categories tag something like this:
{exp:channel:categories}
    <a href="/mcf/people/partner/{cat_template}/{category_url_title}">{category_name}</a>
{/exp:channel:categories}

That would be a great solution but it only works with one category group, I can’t use the same {cat_template} tag for all my Category Groups…

       
lando's avatar
lando
5 posts
8 years ago
lando's avatar lando

I eventually ditched Category Groups altogether and used Parent/Child category relationship… thanks for your help anyway!

       
Rob Allen's avatar
Rob Allen
2,950 posts
8 years ago
Rob Allen's avatar Rob Allen

No problem, at least you found a way of working round the problem, there’s always more than one way with EE!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.