This site has been archived. To learn more about our current products Ibexa Content, Ibexa Experience, Ibexa Commerce head over to the Ibexa Developer Portal

eZ Community » Blogs » Thiago Campos Viana » Tip: Javascript and eZ publish...


Tip: Javascript and eZ publish communication using user preferences

Friday 19 August 2011 12:33:28 am

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

In this post I will show an easy way to make eZ publish 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)}";
$("#var_test").change(function() {
      url: (prefs_url+"/"+$("#var_test").is(":checked")),
      success: function(){}

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?

Proudly Developed with from