Where to include static javascript in Yesod project?

I have a local static Javascript file that I want to include on the site. It is desirable that all static Javascript files are combined into one file, but I want to manage these files separately. Where should Javascript static files be included in the Yesod project?

+7
source share
2 answers

There is a more specific solution.

Example:

import Yesod.Widget (addScript) -- given a file path of static/js/my-script.js addScript $ StaticR js_my_script_js 

If your project is partially compiled, you may receive an error message:

 Foundation.hs:...: Not in scope: `js_my_script_js' 

Then either

  • unix tap the StaticFiles.hs module, which generates route characters by calling staticFiles

  • or clean your assembly and restore it and it will disappear.

Hooray!

You can read about this also in my / (your) wikipedia article . Feel free to fix and complete it.

+14
source

You can use addWidget in your defaultLayout function to add it to widgets that are combined into a single file.

For example,

 defaultLayout widget = do ... pc <- widgetToPageContent $ do $(widgetFile "mywidget") ... other stuff here ... ... 

Now just put the file named mywidget.julius in the templates directory and it will be automatically included on all pages.

+2
source

All Articles