javascript - How to use Redux Framework Text Field option for Simple Weather JS -


hello using simple weather js (http://simpleweatherjs.com/) in wordpress theme showing live weather , options using redux framework. i've create text field "name of city" , option unique id > " cpv-hm-cat-op-8 ". preview of redux framework option below.

array( 'id'       => 'cpv-hm-cat-op-8', 'type'     => 'text', 'title'    => __( 'name of city', 'redux' ), 'desc'    => __( 'write city want show in weather', 'redux' ), 'default'  => 'new york', ),  

now want use option in simple weather js file , want output, when input name of city show in weather of city. simple weather js option =>

  $.simpleweather({     location: 'new jersey',     woeid: '',     unit: 'c',     success: function(weather) {       html = '<h2><i class="symbol-weather  icon-'+weather.code+'"></i> '+weather.temp+'&deg;'+weather.units.temp+'</h2>';       html += '<ul><li>'+weather.city+'</li>';         $("#weather").html(html);     },     error: function(error) {       $("#weather").html('<p>'+error+'</p>');     }   }); 

here "location" want add redux plugin option. not working.

  $.simpleweather({     location: '<?php global $cpv; echo $cpv['cpv-hm-cat-op-8'];?>', 

kindly me how can add there redux framework option.

i've found solution, works me, don't know if it's ideal solution.

my solution adding value head of page, it's accessable further hooks. make sure code loaded before code needs code (fe load other stuff footer it's used be)

in function.php add

add_action ( 'wp_head', 'yourjs' ); function yourjs(){ global $cpv; //your global redux var ?>   <script type="text/javascript">      var weatherinfo = <?php echo json_encode( array(           'city' => $cpv['cpv-hm-cat-op-8'],          'zip' => $cpv['cpv-hm-cat-op-7'], // example value in array        ) ); ?>   </script><?php } 

this put in header on page like:

<script type="text/javascript">      var weatherinfo = {"city":"austin","zip":"12345"}  </script> 

so have array of values can access in code - call var.

hope helps you.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -