Routing hooks in Phoenix - How to modify rendered HTML before output?

If you’re just wanting to understand how Phoenix works I’d start poking around Phoenix.Endpoint(phoenix/endpoint.ex at master · phoenixframework/phoenix · GitHub) as this is the Phoenix entry point of each request. That’s a bit of a rabbit hole so sorry I can’t be more specific… perhaps someone else here can. As far as I know, though, there is no provided way to do this since, as @kokolegorille alludes to, there is no benefit to doing this. Phoenix parses templates to iodata which, for the sake of simplicity, is a highly efficient way to build strings that avoids copying. Converting it to a string at the end to remove whitespace would almost certainly negate any benefit that came from using iodata.

EDIT: Here is a good user-provided explanation of iodata.

1 Like