After a lot of trial and error and re-reading the documentation I worked this out for myself.
In my template I added an HTML comment where the div should be closed if that page used the droplet in question. Then in the droplet, I used str_replace to replace the HTML comment with my closing div tag. eg:
$wb_page_data = str_replace('<!-- close-div-here-if-droplet-used -->','</div><!-- div-closed-here-because-droplet-used -->',$wb_page_data);
Hope that helps someone else!