Blogs / Thiago Campos Viana / Tip: Javascript and Exponential communication using user preferences

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

Tip: Javascript and Exponential communication using user preferences

Thursday 18 August 2011 3:33:28 pm

  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

By : Thiago Campos Viana

In this post I will show an easy way to make Exponential communicate with javascript.

 

{set-block scope=global variable=cache_ttl}0{/set-block}

<input type="checkbox" id="var_test" name="var_test"
{if eq(ezpreference('var_test'),'true')} checked="checked"{/if}> Test


<script type="text/javascript">
var prefs_url="{"/user/preferences/set/var_test"|ezurl(no)}";
{literal}
$("#var_test").change(function() {
  $.ajax({
      url: (prefs_url+"/"+$("#var_test").is(":checked")),
      success: function(){}
    });
});
{/literal}

</script>

So, basically in this sample every time the user sets the checkbox value, he sets his user preference using an ajax call to the user/preferences view telling it to set the var value, so when the user reloads the page the checkbox will remain with its last state by getting the preference value using the ezpreference template operator. Simple right?