I can imagine, you want to add CSS or JS for an image gallery only, if a gallery section is in the page. And the answer is "yes, you can". There are, as always, many ways to do so. First: do I understand you correctly? If not please clarify your use case.
a usual way is something like the following code:
Code to be output if there is at least one "active" section based on one of the given templates.
This version also supports multiple section uids. Of course you could write the same a little shorter by using a combined condition (&& instead of chained filter/map) but I prefer code like the above because I think it is better readable as it kind of describes the steps.
You could also start with !#global.page... and use isEmpty() at the end but that little ! is too easy to miss in my opinion.