So what I'd like is:
If URI would look like {username}, load _thisTemplate.
Couldn't find the way without solid point like author ID.
So what I'd like is:
If URI would look like {username}, load _thisTemplate.
Couldn't find the way without solid point like author ID.
I would not particularly advise creating a uri pattern that was just 'www.site.com/username' because usernames can essentially be anything which might cause routing conflicts (i.e. if the username is 'index' for example). You could however use something like 'www.site.com/members/username' or 'www.site.com/u/username'.
One way to do this would be to add a route using a 'subpattern'. For more info check out the routing docs on accessing subpatterns in your templates.
Here is the example given in the docs, which provides the variables 'year' and 'month' to the template that correspond to the matched uri segments (i.e. `news/2015/02'):
'news/(?P<year>\d{4})/(?P<month>\d{2})' => 'news/_archive',
You could essentially do the same thing but with a 'username' variable.
'u/(?P<username>[^\/]+)' => '_thisTemplate',
You can then use the 'username' variable in your template to retrieve the corresponding user.
{% set user = craft.users.username(username).first() %}
{% if user %}
{{ user.firstName }}
...
{% else %}
{% redirect 404 %}
{% endif %}
{% set user %} you're overwriting Craft's global user variable (i.e. the currently logged in user). Not a problem in most cases, but probably worth mentioning.
– Mats Mikkel Rummelhoff
Jun 01 '15 at 18:06
(?P<username>[^\/]+)
– carlcs
Jun 01 '15 at 20:30
<a href="{{ url('u/' ~ entry.author.username) }}">{{ entry.author.username }}</a> is what I have, but with 404 redirection. But anyway, some time ago I posted the question, if there would be possible to add a prefix to variable, like popular '#username'. In this case we wouldn't have to worry about any conflicts. Thanks to @Douglas McDonald, @mmikkel and @carlcs on participating this answer.
– Dominik Krulak
Jun 02 '15 at 08:08
/people/phil-collins/832... – tom Jun 01 '15 at 12:53