- Install Lottie Player:
npm install --save @lottiefiles/lottie-player
- Require it at
app/javascript/packs/application.js
require('@lottiefiles/lottie-player');
- Set webpacker to load jsons
static_asset_extensions:
- .json
extensions:
- .json
-
Put your lotties jsons wherever you want (e.g.
app/javascript/images/lotties
-
Render
lottie-player
tag in your html:
#my-lottie-container
%lottie-player{ autoplay: true, loop: true, src: asset_pack_path('media/images.lotties/mylottie.json') }
- Profit
Extra:
- Create a view helper to handle your lotties paths:
def lottie_pack_path(name)
asset_pack_path "media/images/lotties/#{name}"
end