I'd like, in my code, to be able to trigger a layout instead of doing it in the UI.  This gives the flexibility to change layouts based on dynamic data (which isn't always usable in the UI). 

This would be the layouts equivalent of a page template suggestion in Drupal 7, I suppose.

Is there a preprocess function or something else I can use to change the layout that's used?

Comments

I don't think this answers your question, but it might help someone with a related question. 

The layout template for any given layout is stored in config and you can programmatically change the config file to change with layout template is associated with a given layout. 

I have an install file for a recipe that provides examples of how to modify blocks on a layout. 

https://github.com/backdrop-contrib/digital_agency/blob/1.x-1.x/digital_agency.install

For your purposes, would hook_layout_load work?

https://docs.backdropcms.org/api/backdrop/core%21modules%21layout%21layo...

 

Thanks for the response and probably good info for someone, but you're correct that it's not really what I was looking for.  

I need to be able to run code and that code determines which layout a particular page uses.  So instead of using the UI, I'd be setting the layout in a module's custom code.