trim supports variable value (on/off). 

e.g.
set $html_trim "on";
if (Some Condition) { set $html_trim "off" }
trim $html_trim;
trim_js $html_trim;
trim_css $html_trim;