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?
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
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 theHandler.Foo
module, then touch (or save from your editor) thesrc/Handler/Foo.hs
file and reload GHCi.