So you are actually trying to get the passed value to literally be {{id}} and not just $id? Because if you are just trying to pass the value, just do URL::route('viewUser', [$id]);
.
Thanks for the reply, but yeah I'm want the literal '{{id}}'. I'm using Blade to pre-process Mustache templates, so I want
URL::route('viewUser','{{id}}')
to output
https://app.dev/users/{{id}}
What is it currently outputting? Just a urlencoded version of what you want? If so, why not just do urldecode(URL::route('viewUser', '{{id}}'))
?
Or are you saying blade is trying to process {{id}}
? If so, @{{id}}
.
Right now,
URL::route('viewUser','{{id}}')
will result in the { and } getting urlencoded:
https://app.dev/users/%7B%7Bid%7D%7D
I appreciate your efforts nesl247, but this is not an issue with Blade really. It's view-related only in that I want the URL for use in a view.
I had a similar issue with HtmlBuilder::link() which by default will escape the title attribute. I can just extend it with my own HtmlBuilder::link() implementation and I'm good to go. But UrlBuilder gets loaded so early, I haven't been able to figure out how to extend or replace it with a custom implementation.
Why not just:
{{ URL::route('viewUser') }}@{{id}}
??
Yeah underparnv I should've mentioned that. That works, but it quickly gets messy and/or difficult, e.g. when the {{id}} is not at the end of the URL. For example if my desired output were this:
https://app.dev/users/{{id}}/messages
I finally came up with a "good enough" solution. Since all I care about in this case is allowing curly braces for use by Mustache, I decided to just extend the URL facade, and explicitly declare the route() method there with a simple str_replace() call. Here's a gist: https://gist.github.com/anaxamaxan/8df15263e9f25cda9872
This won't work for HTML::linkRoute() but in my case I rarely use that method anyway; instead I do HTML::link(URL::route()) as a habit, so the output goes through my custom facade and everything works.
The interesting take-away is to remember that facade classes depend on __call(). You can bang out some custom functionality just by explicitly declaring the method within a custom facade.
Duh...was only looking at the example provided and not thinking about the problem completely. Nice solution!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community