The permalink
variable will take into account template group and template if you specify them. So for example...
{permalink="products/detail"}
would give you...
http://example.com/products/detail/1
...where "1" is the entry id and "detail" is a template in the "products" template group.
But, as far as path variables go, my preference when building links that involve template paths is to use title_permalink
(works just like permalink above but uses the url_title
instead of the entry_id
).
Finally, as you noticed url_title
and entry_id
don't take into account template group/template paths. They just reference a given entry (either by the url title or the entry id). But they are useful in manually building paths to single entries.
So if you prefer, just use a root-relative path in conjunction with url_title
. For example...
/products/detail/{url_title}
As long as you are removing index.php the above works great. I have started to use this more than I do the path variables.
And to answer your other question:
Then maybe in my templates /products/index, I do a check on
{segment_2} to decide if I should be displaying the details page or
not? So where does the details template go?
Just put your "detail" template in the "products" template group and any time you load a path that matches /products/detail
(or /products/detail/etc/etc
) that template will be loaded as you'd expect. No extra work is required, ExpressionEngine will do that automatically.
If, instead (as you indicated in your comment), you are wanting to include all the logic and display of a "detail" template in your single index template and forego a second template, then doing a couple simple conditionals like...
{if segment_2 == "detail"}
detail-template stuff here
{/if}
{if segment_2 != "detail"}
non detail-template stuff here
{/if}
...is often enough to accomplish what you described. If it is not, or if more complicated template logic is needed, definitely take a look at Switchee.