Detecting whether code is being run in Dashboard

Permalink
Hi,

I made a pretty hefty template modification to the Auto-nav block - and now when an instance of which gets added to the scrapbook, it makes everything explode in fiery shrapnel if you view the scrapbook in the Concrete5 back-end.

So, what I've been looking for is an easy way of detecting whether my code is being run/viewed in the dashboard/scrapbook - so I could make a conditional exception in this case (something similar to isEditMode in the frontend)

Does something like this exist? After much searching and testing I have not been able to find a way to detect whether my code is being rendered in the scrapbook vs. the frontend... Any ideas out there? :)

Thanks!

Psst

 
jordanlev replied on at Permalink Reply
jordanlev
I think when you're in the global scrapbook, you're still under the dashboard, which always appears in the URL. So you could check the url for the word "dashboard" with something like this:
<?php
if (substr(Page::getCurrentPage()->getCollectionPath(), 0, 20) == '/dashboard/scrapbook') {
   echo "YOU ARE IN THE DASHBOARD";
} else {
   echo "NOT IN THE DASHBOARD";
}
?>


Note that it's weird your block blows up in the global scrapbook -- that might be indicative of another problem. Is it a style thing (like CSS is interfering), or a javascript thing (functionality is broken)?
Hammertime replied on at Permalink Reply
Thanks - I'll try it out. And yeah, it's a combination of all of the above (javascript/styles duplication) AND a php include error