xen:callback is not working in js in template

Dadparvar

Well-known member
Hi,

In a template, I need to write this array, in order to let my add-on works:
Code:
[ 'song1', 'song2', 'song3' ]
When I write it manually, it works (this part is a part of my js code in template)
But I need to read it from a php file. So I created a php file with this code:
PHP:
<?php

class Dadparvar_test_Helper_Filelist {
    public static function helperTest() {
    echo " [ 'song1', 'song2', 'song3' ] ";
    }
}
?>
and instead of writing that code manually, I added this in my js:
Code:
<xen:callback class="Dadparvar_test_Helper_Filelist" method="helperTest"></xen:callback>

But it doesn't work.

Any Opinion will be appreciated.
 
Callbacks should return their output, not echo it (though we do catch output).

But otherwise, what does "it doesn't work" mean? What happens specifically?
 
Callbacks should return their output, not echo it (though we do catch output).

But otherwise, what does "it doesn't work" mean? What happens specifically?
I changed it to return. But still not work.
I mean: if it works, then it will show something in profile tab. But if not works, then nothing will be shown in profile tab.
For more detail, When I use it in my js code:
Code:
    $.Cassette.defaults     = {
        // song names. Assumes the path of each song is songs/name.filetype
        songs            : [ 'song1', 'song2', 'song3' ],
        fallbackMessage    : 'HTML5 audio not supported',
        // initial sound volume
        initialVolume    : 0.7
    };
It shows this in result:
2016-04-16_12-59-04.webp

But when I use this code in js in template:
Code:
    $.Cassette.defaults     = {
        // song names. Assumes the path of each song is songs/name.filetype
        songs            : <xen:callback class="Dadparvar_profilemusic_Helper_Filelist" method="helperProfilemusic"></xen:callback>,
        fallbackMessage    : 'HTML5 audio not supported',
        // initial sound volume
        initialVolume    : 0.7
    };
and also this code in php file:
PHP:
<?php

class Dadparvar_profilemusic_Helper_Filelist {
    public static function helperProfilemusic() {

    return " [ 'song1', 'song2', 'song3' ] ";
    }
}
?>
It shows nothing in result.
 
Assuming your js expects an array and that the code in the php is suppose to be a 5.4+ array, you're returning a string literal, not an array.

I believe you want to return this...
Code:
return [ 'song1', 'song2', 'song3' ];

Could be wrong though. ;)
 
Top Bottom