Yesod route interpolation in Julius via widgetFile

195 views Asked by At

I think @{SomeRouteR} should work in .julius files, as described in:

https://www.yesodweb.com/book/shakespearean-templates#shakespearean-templates_julius_javascript

Everything was working when I first had this in my Handler:

toWidget [julius|   
                        $("#examplespan").click(function(){                                                                               
                            $.ajax({                                                                                                      
                                url: @{ExampleR},                                                                                 
                                type: "POST",   
                                ...

                        |]

But now that I've changed my Handler to work like this:

$(widgetFile "example")

I added this code in example.julius:

                        $("#examplespan").click(function(){                                                                               
                            $.ajax({                                                                                                      
                                url: @{ExampleR},                                                                                 
                                type: "POST",   
                                ...

I now get the error:

[Error#yesod-core] expected EUrl but got Nothing for: DerefIdent (Ident "ExampleR")
CallStack (from HasCallStack):
  error, called at ./Text/Shakespeare.hs:441:27 in shakespeare-2.0.20-3iMfZ8A5DXH3Twhu6IoWNc:Text.Shakespeare @(yesod-core-1.6.9-7g4SwkDmJJ261rdNBKrLzX:Yesod.Core.Class.Yesod ./Yesod/Core/Class/Yesod.hs:662:5)

What am I doing wrong?

1

There are 1 answers

1
Jezen Thomas On BEST ANSWER

There might not be anything wrong here. I will copy in a troubleshooting note I have written previously for my company.


DerefBranch Error from a Template File

I made a change in a template ({*.hamlet,*.cassius,*.lucius,*.julius}) and I get an error like this:

\"rawJS\")) (DerefBranch (DerefIdent (Ident \"tshow\")) (DerefIdent (Ident
\"errors\")))\nCallStack (from HasCallStack):\n error

This is an issue with [I believe] template Haskell and the way that we're compiling. Maybe it's some GHC flags, maybe it's GHCi itself, I'm not sure.

You can resolve this by touching the file that references the template, e.g., if your template file is templates/foo.julius, and you reference it with $(widgetFile "foo") in the Handler.Foo module, then touch (or save from your editor) the src/Handler/Foo.hs file and reload GHCi.