I want to remove template name from URL. I want to display only template_group/entry-name. Is this possible?
-
Possible duplicate of Remove template segment from URL. Also see Strict URLs / Removing one template group name – Alex Kendrick♦ Oct 15 '13 at 12:39
-
Alex - both those questions refer to removing the template group, which is very different to removing the template name. Albeit both can be resolved with similar add-ons, the native solutions would be quite different, so justifies a separate question. – Peter Lewis Oct 15 '13 at 16:29
-
I misinterpreted the question. Close vote retracted and +1 for your answer @PeterLewis ;) – Alex Kendrick♦ Oct 15 '13 at 20:47
You can use the Template Routes plugin to override the default routing.
You'd add something like this to your index.php:
$config['template_routes'] = array(
'template_group/:any' => 'template_group/template_name'
);
and then just do something with the $1 value in the template.
As Robson & Bhashkar have stated, use the index template in the template group to do the channel:entries tag pair - therefore doing away with the template reference in the URL. If you target template_group, it automatically uses the index template without you specifying /template_group/index.
You're trying to utilise the same template (template_group/index) for both the listing and the details - that's absolutely fine, just utilise no_results...
Let's assume template_group is "blog", the URLs you want are:
- /blog (listing)
- /blog/my-article (details - not /blog/details/my-article)
Assume you're accessing the entry details first, so blog/index template:
{exp:channel:entries
channel="blog"
dynamic="yes"
require_entry="yes"
track_views="one"
disable="member_data|pagination"}
{if no_results}
{embed=blog/listing}
{/if}
... display of blog details page ...
{/exp:channel:entries}
This will attempt to pull an entry based on the URL - if it can't match it, it will fall into the no_results conditional and embed the listing page...
Template blog/listing (note this template isn't the URL!)
{exp:channel:entries
channel="news"
dynamic="no"
orderby="date"
sort="desc"
paginate="bottom" paginate_base="/blog"
limit="10"}
...listing details...
{/exp:channel:entries}
The easiest way will be just put the code within the "index" template of that template group. By doing it, you can have the URL like template_group/entry-name.
-
@ Bhashkar sir i am already using "index" template for article list page and for article detail page i am using template_group/template/article-name so now i want to remove details and i want to use template_group/article_name now how this is possible ? – Bhavin Vora Oct 15 '13 at 11:08