Phoenix + Leaflet.JS

101 views
Skip to first unread message

taufiq ibrahim

unread,
Jul 18, 2016, 1:48:37 AM7/18/16
to elixir-lang-talk
Hi all,

I just learned using Phoenix framework for couple of days.

I tried include a Leaflet.JS inside the project.
I already:
- successfully create a new page called /maps
- the page can be loaded
- tried to put leaflet.js and leaflet.css inside web/static/vendor
- create a div and script to call leaflet map in web/templates/maps/index.html.eex

However when I load the page the map was not loaded with console says : Uncaught ReferenceError: L is not defined

It seems that the JS was not loaded but if I checked the sources using Chrome inspect element the JS was already loaded.

Am I missing something here? Any help would be appreciated.

Thanks

OvermindDL1

unread,
Jul 18, 2016, 10:34:31 AM7/18/16
to elixir-lang-talk
Is it loaded 'before' your code?  Since it does not seem to follow ES6 styling the vendor directory is correct, but because of that order will matter (it does not with ES6 javascript).  You could wrap the code in ES6 migration code then import it as normal, though easier might be to put it in the files.javascripts.order.before section so it is included before anything else.

Also the css file should usually still be in the css folder (usually, does not matter on output).  Vendor is generally for files that need to be ignored for post-processing by brunch (non-ES6 javascript in the default phoenix case).

Also there are more people talking on the main Elixir discussion site at https://elixirforum.com/ :-)
Reply all
Reply to author
Forward
0 new messages