Is it possible to write a partial for the class of div?

Hello everyone, I am trying to implement light/dark mode on my site where different pages use different themes and I was wondering if I’d be able to use a partial to define the class of the body in my default baseof layout like so:

<body class='{{ block "theme" . }}{{ end }}'>

Is this the correct way of doing this or is there some other way?

I don’t know if it’s the best way to do it or not, but it definitely works; I’m refactoring my theme to use something like this right now.