Ajax call within rain template

mpisanchikmpisanchik Posts: 9Member

Is it possible to make an Ajax call within a template and pass the response to a snippet .rain as a parameter?

3 comments

  • Adrian SamuelAdrian Samuel Posts: 515Moderator, Lightspeed Staff moderator

    Hey @mpisanchik, were you able to successfully make the API call?

    You can find some information in some public documentation here: https://cruftlesscraft.com/passing-data-from-twig-to-javascript

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • mpisanchikmpisanchik Posts: 9Member

    Hey @Adrian Samuel thanks for your response. I was able to make the AJAX call but the problem I was running into was that I wanted to pass the AJAX response (which is javascript) into a twig snippet. I know I can do the reverse which is passing from twig to javascript but I was wondering if it was possible to pass from javascript (AJAX) to twig.

  • Adrian SamuelAdrian Samuel Posts: 515Moderator, Lightspeed Staff moderator

    Hey @mpisanchik ,

    I imagine this isn't possible because the Twig is rendered server side from our back-end and the JS AJAX call happens client-side (on the browser only after the Twig has already loaded), so there isn't a way you could affect a change in the Twig output from a call that happens afterwards.

    You would simply change the resulting HTML that generated with Javascript

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

Sign In or Register to comment.