Question

Photo of Arran France

0

Using Lava Attributes in Java Script

I'm using Bootstrap Tours to create page tours to help our staff navigate through Rock.

I'd like to personalise these tours with information like the user's name. Is it possible to pass Lava values to Javascript?

 

  • Photo of Trey Hendon III

    1

    Cool idea!  Should work fine as long as you're creating the JavaScript in an HTML Block.  Here's an example:

    <p>Click the button to display an alert box with nick name.</p>

    <button onclick="myFunction()">Try it</button>

    <script>
    function myFunction() {
        alert("{{ Person.NickName }}, I am an alert box!");
    }
    </script>

    I'd recommend casing the Lava to see if they're logged in or not and give some generic fall-back just in case.

    • Arran France

      This works. As does
      <script>
      $(function () {
      $('[data-toggle="popover"]').popover()
      })
      </script>
      <button type="button" class="btn btn-lg btn-danger" data-toggle="popover" title="Test" data-content="Hey {{Person.NickName}}">Click to toggle popover</button>


      Alas I can't get Lava working with bootstrap tours. I'll have a bit of a further play when I get a chance.