Jump to content

Accessing widget parameters in js


LZDigital

Recommended Posts

Posted
$('div.example').data('twurl');

I'm trying to use this code to retrieve the data from:

<div id='example' data-twurl='mydata'>
</div>

I'm trying to do this with a widget, but it's not working, any ideas?

Posted
8 hours ago, ReZnoR said:

$('div.example').data('twurl');

I'm trying to use this code to retrieve the data from:


<div id='example' data-twurl='mydata'>
</div>

I'm trying to do this with a widget, but it's not working, any ideas?

Your selector is wrong - it should be

$('#example').data('twurl');

 

Posted
22 hours ago, ReZnoR said:

I know this sounds weird, but I want to be able to use the parameters passed to a template in JS, how do I go about doing this?

Set(specifically modified to support use in a template, remove the {{}} if working in a PHP file):

{{\IPS\Output::i()->jsVars['my_data_key'] = $data;}}

Read in JS:

var myData = ips.getSetting('my_data_key');

Using the data attributes properly tends to be a bit more complex, as you end up diving into making controllers and/or models in the js framework.

Posted
1 hour ago, Marcher Technologies said:

Set(specifically modified to support use in a template, remove the {{}} if working in a PHP file):


{{\IPS\Output::i()->jsVars['my_data_key'] = $data;}}

Read in JS:


var myData = ips.getSetting('my_data_key');

Using the data attributes properly tends to be a bit more complex, as you end up diving into making controllers and/or models in the js framework.

I don't know what I'm doing wrong, but I am doing exactly as you did here and I still cannot read the variable in the JS says undefined. The template variable only contains a URL so I don't know how else to get it there.

Posted

I checked the jsVars array, and it only contains a couple of items, including my custom one. But when I print out the object in JS to check it, it contains the info of the main jsVars object with baseURL and all of those but not my custom one.

How does my js file access only stuff for that plugin? Like my jslang file, my javascript file can't access it.

  • 1 year later...

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...