The reason that it’s not working is that you’re not using get_template_part(). When you use get_template_part() WP declares the global $post variable for use in your template, along with many other global variables that are used in templates.
You either need to switch to get_template_part() or you need to declare the global variables yourself at the top of your file global $post;