Your code looks well and considerations are correct. In order to achieve your goal, I’d collect HTML and wrap it up like this:
Instead of calling <?php dynamic_sidebar($sidebar_id); ?>
use <?php dynamic_sidebar_replaced($sidebar_id); ?>
with a function (add it to functions.php) below:
function dynamic_sidebar_replaced($sidebar_id) {
if (is_single()) { // Optionally, to ensure you're at the single post template.
ob_start(); // Start gathering output
dynamic_sidebar($sidebar_id);
global $post;
$POST_NAME = $post->post_name;
$sidebar = preg_replace('/\{(POST_NAME)\}/e', "$$1", $sidebar);
ob_end_clean();
echo $sidebar;
return '';
}
dynamic_sidebar($sidebar_id);
}