Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require('zappajs') ->
- @use 'zappa'
- @enable 'default layout'
- @get '/': ->
- foo = 'bar'
- @render 'index', foo: foo, hardcode: { coffee: export_params }
- @view index: ->
- @scripts = ['/zappa/jquery']
- coffee ->
- $(document).ready ->
- alert params.foo
- # Embed the @render params into window.params (aka `params` since
- # window is the client-side Javascript context).
- export_params = (coffee) ->
- text "<script> window.params = {};"
- for name, value of @
- try text """
- window.params[#{JSON.stringify name}] = #{JSON.stringify value};
- """
- text "</script>"
- coffeescript coffee
Add Comment
Please, Sign In to add comment