Inline JQUERY is not allowed anymore in Elgg 2.11 – How insert PHP code in JQUERY Script?

I load JQUERY code  with: elgg_require_js('foo‘);
But I get errors from script debugger because elgg does not recognize  the php code (see examples)
What can I do?

Example 1:

$('#output-pic-rated_member').attr("src", '<?php echo $elgg_site_url?>mod/audit/images/codes/' + parseInt(data['member']['rated']) + '.jpg');

 $('#outputdialogtext1_member').html(data['member']['count'] + " " + '<?php echo elgg_echo('member_audit_main_counts'); ?>');

Example 2:
 
var proxy2 = new wijhttpproxy({
url: "<?php echo $elgg_site_url ?>/audit/db_audittyp",
dataType: "json",
 data: {
featureClass: "P",
style: "full";
maxRows: 12
},
key: 'audits'
 });

  • You don't need to use PHP for these.

    var $ = require('jquery');
    var elgg = require('elgg');
    
    // prefix with site url
    elgg.normalize_url('mod/path/to/file'); // consider registering a page handler instead...
    
    // translate
    elgg.echo('key:to:translate');
    

    If you must use PHP, create your AMD module with a PHP extension, as so foo.js.php and register it as a simplecache view (elgg_register_simplecache_view('foo.js'))

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking