How to find if Umbraco 7 Debugging is Enabled in AngularJS or Javascript in the Backoffice

When creating a new functionality in the Umbraco 7 backoffice such as a property editor or custom section, it is sometimes necessary to print out some debugging information to verify that the models are what you expect.

Rather than commenting out your {{myModel | json}} AngularJS bindings, why not simply only show them if Umbraco has debugging turned on?

Turns out, this is very easy as Umbraco already has a global ServerVariables collection that you can check:

Umbraco.Sys.ServerVariables.isDebuggingEnabled

If you want to show/hide information based on that in AngularJS, simply assign it to a property on the $scope of your controller:

$scope.showDebug = Umbraco.Sys.ServerVariables.isDebuggingEnabled;

Then check for it in your view:

<div data-ng-show="showDebug">{{myModel | json}}</div>

 

That's it!  

Author

Jason Prothero

Jason leads the team at ProWorks Corporation, an Umbraco Platinum Partner specializing in complex Umbraco CMS builds, integrations, support, and upgrades. With 17+ years of Umbraco experience and an Umbraco MVP, he has led dozens of successful projects from versions as old as Umbraco 4 to the latest Long-Term Supported (LTS) releases. Jason is also leading the charge at ProWorks around AI and how to responsibly integrate AI into Umbraco and websites to create ROI and not simply as a novelty.

comments powered by Disqus
back to top