0

The goal is to have a variable(link) merged with prefix "any special character", that will not break the URL(this was pointed to my about character in URL lately, but in this question, We use "#"). So the final output would be "site.com/#variable" (in my case it is the author of an entry and a link to author's profile.

Also, I'd have to route it to get the correct template loaded. The whole reason behind is, that the current prefix would avoid of potential conflicts with other templates in case, some username will be 'index'.

  • "linkToLeft" is already different from "linkToRight"? – carlcs May 26 '15 at 15:02
  • Understand this as "link" is variable and "ToLeft" and "ToRight" are two different links of type. Both serve different type of content. To you question, Yes it's already different. – Dominik Krulak May 26 '15 at 15:07
  • I'm not sure I'm following "link" is variable and "ToLeft" and "ToRight" are two different links of type.. Maybe edit the original question with some further clarification? – Brad Bell May 26 '15 at 15:49
  • Hope, the question's update will help. – Dominik Krulak May 26 '15 at 16:40
  • 2
    If this gets reopened i'm 99% sure I have a solution... – Alec Ritson Jun 4 '15 at 13:58
4

So from reading your updated answer and looking at the other question you mentioned I would assume you are trying to create prefixed dynamic links that don't conflict with your routing.

For example site.com/about would link to your about page and site.com/#about would load up your custom template.

Problem

The problem with using a # for your trigger is that really this should be used for linking to internal sections on a page and with the above site.com/#about would actually just link to your index page and if you had a <div> with an id of about you'd find the scroll position at that div, so I think using a # is going to give you a lot of headaches.

Solution

Perhaps use the @ sign? if it's good enough for twitter to use then I don't think you'll have many problems using it.

So, in your config/routes.php you would have:

return array(
 '(?P<username>\@\w+)' => '_someCustomTemplate',
);

This will match anything starting with an @, assign it to username a variable in your template and load it up, I tested on the Happy Lager install and it worked like a charm, /about goes to the about page /@about goes to my custom template

So in your custom template you could have the following:

{# This will get rid of the @ #}
{% set username = username|replace({'@': ''}) %}

{% set user = craft.users.username(username) %}

If you want to change the trigger to something else, just change @ in the route expression and then in the replace filter, but that should do the trick for you and avoid conflicts!

on a side note, I replaced @ with a # and it didn't work, just went to the home page

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.