Use Phoenix.Param.to_param/1 directly to generate DOM Element id or not?

Recently I was reviewing the code and in the HEEX template I noticed something like:


We all knew that item is the struct of the main resource we are dealing with on that view and I proposed to change the code to more simple and clear


And overall I thought that we shouldn’t use Phoenix.Param.to_param/1 directly, not only in that context to fetch the param for the DOM element id but also anywhere else in our app code… like leave it to the framework and treat it as “undocumented feature”.

However, co-worker pointed me to generated CoreComponents.table/1 where he got the idea from.

While, I see that in the generic CoreComponent we need to be able to come up with an id for arbitrary input, I still don’t think it’s a right function for the job.


I guess it’s a way of moving the logic for deciding what will be [that part of] the DOM id to the struct itself. Then if you decide you want to use a different part of the struct for the DOM id, you only need to change it in one place.