Search code examples
javascriptphpwordpresshandlebars.js

How to print the object values in WordPress


I want to make changes to the ultimate member plugin template file. enter image description here

Now I want to check the details that are inside the user object but I don't know how to print or var dump the user object can anyone help me with that, please?

Thanx in advance :)


Solution

  • The code you showed us is part of a template object embedded in the HTML your server sends to your user's browser. This object gets interpreted by some Javascript code your server also sends.

    Debugging this stuff is tricky because various languages are embedded in each other. In your case you want to see the data variable. It is in ...

    • Javascript,
    • embedded in a template object,
    • interpreted by other Javascript,
    • embedded in HTML,
    • embedded in php.

    To debug it you first have to guess what is embedded in what. And you need a bit of luck to guess correctly. I am guessing.

    The template itself can contain Javascript code, and you're asking about the value of data in that Javascript code. So, if you want to see that data you can put a Javascript console.log() call into the template for debugging purposes. To do that, change this line

    <# _.each( data, function( user, key, list ) { #>
    

    to this

    <# console.log('data from member grid', data ); _.each( data, function( user, key, list ) { #>
    

    The output from console.log appears in the console tab of your browser's devtools: it's generated by the browser not your WordPress / php server.

    You could, if you want to use your browser devtools Javascript debugger, use this line instead.

    <# debugger; _.each( data, function( user, key, list ) { #>
    

    The debugger will engage right before the _.each loop and let you examine your variables, like data.

    Notice that my suggestions are not debugged, and I have no way to debug them.