derekkraan

derekkraan

[abandoned] Proposal for multiple "~p" sigils

I have been using a multi-endpoint setup in my app, just because I think it makes the most sense for a multi-subdomain app. This worked well enough with the old style of route helpers, since I could call them with their fully qualified module names.

Now with the introduction of ~p, things have become more complicated. The crux of the issue is: there can only be one ~p sigil defined per module. This means that it is not possible to use verified routes for multiple routers in the same template.

The result is that I have resorted to using just string literals in the places where cross-domain links are present.

My proposal is to make the sigil that is defined customizable, with a default to p when no other has been defined.

Usage would look something like this:

use Phoenix.VerifiedRoutes,
  endpoint: MyApp.Endpoint,
  router: MyApp.Router,
  statics: MyApp.statics,
  sigil: "MYAPP"

And then you would be able to use the sigil like this: ~MYAPP"/my_path".

This would make it possible for several sigils to be defined in a single module.

I’d be happy to provide a PR if there is agreement that this would be a good addition to Phoenix.

[edit: apparently path/3 and url/3 exist and I just didn’t know about them. In light of that it seems unlikely that this proposal will be accepted]

Most Liked

LostKobrakai

LostKobrakai

You can use verified routers also with path(conn_or_socket_or_endpoint_or_uri, router, ~p"…").

derekkraan

derekkraan

still I am not a friend of that

Discussion on that change was pretty heated so I don’t think you’re the only one. Still, it’s there.

by convention

I think with new capabilities there will be new conventions.

Personally I’m very much in favour of the new sigil capabilities. There are a thousand new sigils that one could imagine, and the all upper caps means that you will readily be able to see where magic is happening.

christhekeele

christhekeele

As a thought experiment, an interesting alternative would be to provide the desired router as a suffix.

You could hack around how sigils allow lists of characters at the end, to support things like Regex modifier flags such as ~r/(^(?<line>.*?)$/m for multi-line regexes.

Sadly, ~p"my_path"MyApp.Router would not work because of how the . gets parsed; these modifiers only accept ASCII letters and digits. So we’re back to doing something like configuring an alias in your Router, but with even nastier metaprogramming to implement:

use Phoenix.VerifiedRoutes,
  endpoint: MyApp.Endpoint,
  router: MyApp.Router,
  statics: MyApp.statics,
  sigil_specifier: "myapprouter"

~p"/my_path"myapprouter

which is frankly worse.

Where Next?

Popular in Proposals: Ideas Top

DaAnalyst
@chrismccord @josevalim @steffend Been using colocated JS for a while and I keep on stumbling on the same limitation: there is no way (a...
New
sezaru
When writing my code, I always find __MODULE__ very useful to use as alias of that module “inner dependencies”, ex: alias __MODULE__.{Im...
New
manhvu
In a large repo, working with module need to add alias too much is quite annoyed and not good for organizing code. I think better add su...
New
bianchidotdev
I came across a blog post that implemented a function guard for a liveview socket connection’s presence. It seems like a really ergonomic...
New
engineeringdept
In 2026 double submit/session tokens are no longer necessary to prevent against CSRF attacks. Instead, we can use the Sec-Fetch-Site head...
New
bartblast
This could resolve to {[a: 1, b: 2]}. Was it ever considered to allow such syntax? Notice this: {:abc, a: 1, b: 2} and this: my_fun(:abc,...
New
bamorim
Story behind Recently, I gave a talk on a meetup about improving performance of Phoenix applications and the example app was a LiveView ...
New
i-n-g-m-a-r
When debug_errors: true javascript can be executed. &lt;html&gt; &lt;body&gt; &lt;form id="xss" action="https://domain.com/NateMai...
New
caslu
Recently (last week) this PR was merged in Ruby on Rails repository and i thought it could be nice to have in phoenix, basically what it ...
New
eagle-head
Hi everyone, I’ve been researching Content Security Policy Level 3 support in Phoenix and wanted to share my findings and a proposal for...
New

Other popular topics Top

skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement