smorfer

smorfer

Show GitHub Profile

Threads by smorfer

HSX: Conversion from Action to Route through ToHtml?

I started learning IHP and after finishing the "Your first project" part in the IHP Guide, I saw how actions where used as routes in two ways:

  • <a href={pathTo NewPostAction}><...
  • <a href={ShowPostAction}><...

Changing any of them to the other breaks neither of them

Now, looking at the HSX Guide, it states:

"If the variable is any other custom Haskell data structure: it will first be converted to a string representation by calling show on it. You can add a custom ToHtml (import it from IHP.HtmlSupport.ToHtml) instance, to customize rendering a data structure."

As I looked at the ToHtml class, I reasoned it should probably work in the way, that if there is no ToHtml Instance for a "custom haskell data structure", it will just use the Show instance of ToHtml, which is derived for any generated Controller Actions. I figured, this must mean in the conversion process from hsx to html, there is no explicit use of Show but ToHtml is used for any data, defaulting to its Show instance.

If I'm right, does that mean, that there are generated ToHtml instances for the Controller Actions, which would convert them? A derived Show instance of a normal algebraic data structure would just return the typical string representation said structures, so there must be a conversion to a href-compatible path. I couldn't find the ToHtml instances, but still with or without pathTo, the action gets translated to a path in HSX(Maybe I'm wrong here?). pathTo's usage would be to manually change a path, and if no change of the path is needed, one can just write "{Action}" to get the standard path to it.

Maybe I misunderstand something crucial here, and I would be happy to change that. My future self thanks you!

smorfer , in General