Reputation: 25
I started using SilverStripe php CMS/Framework. Is there any way we can var_dump
a variable in the .ss templates ?
Upvotes: 2
Views: 2699
Reputation: 51
Put either of these in your PHP code, most often in your Controller, where $myVariable is either a custom function or simply a variable to test what data is coming back. It should show up at the very top of your web page when you reload it...
Debug::show($myVariable); // formated output
// vs
print_r($myVariable); // unformated output
I can't recall if there's an actual .ss template variable that does anything like this other than creating a custom function and calling it like a normal template variable, which is no different then the above two options.
Upvotes: 0
Reputation: 889
You can use Debug::dump($theDataYouWantToDump)
to dump any data in the browser or command line anywhere in your php Silverstripe codebase. Also, you can run .debug
off of any DataObject, ViewableData object in the .ss
template to view the underlying data.
Example, you can do this in your Silverstripe PageController
class to dump out test data.
public function init(){
parent::init();
Debug::dump("dumping test data from the controller init function");
}
Or you can do some thing like this in your .ss
template to dump out test data.
$Page('home').debug
Hope that answers your question.
Upvotes: 4
Reputation: 219
Variables in SilverStripe's templates are pulled in via the controller. You should be able to var_dump
the variable from the controller using PHP.
https://docs.silverstripe.org/en/4/developer_guides/templates/syntax/#variables
Upvotes: 0