Mick23 Posted June 20, 2022 Share Posted June 20, 2022 Me again (sorry I'm new at this, so forgive me if my questions seem a bit stupid)! Can somebody point me in the direction of getting the template parameters in my controller js file? eg: <ips:template parameters="$id, $name, $age" /> How do I (can I) access these in my javascript controller code? Link to comment Share on other sites More sharing options...
Mick23 Posted June 20, 2022 Author Share Posted June 20, 2022 For a little more context... I'm trying to write a game where a word is selected from the database at random (working) but I need to access that string value in the javascript code in order to manipulate it. Do I have to write a function in the php controller in order to fetch the phrase rather than passing them in as parameters to the template? If so, how do I call it from the javascript? Link to comment Share on other sites More sharing options...
Solution Nathan Explosion Posted June 20, 2022 Solution Share Posted June 20, 2022 Add this to your template: {{\IPS\Output::i()->jsVars["variable"]=$value;}} Then use this in your JS code (assuming it is using the IPS framework): alert(ips.getSetting('variable')); Mick23 1 Link to comment Share on other sites More sharing options...
Martin A. Posted June 20, 2022 Share Posted June 20, 2022 Or add it as attributes to the element where you define your controller. <div data-controller="my.controller.here" data-var="{$var}"> Then access with in your controller this.scope.attr( 'data-var' ) Link to comment Share on other sites More sharing options...
Recommended Posts