Using is_page_template inside loop

I managed to get the required result like this:

<?php
  $template = get_page_template_slug();

  if ($template === 'my-template.php') { 
   //do stuff
  }
?>

error code: 523