Get the current item ID

Is there a proper way to get the ID of the current item being viewed?

I'm doing it like this at the moment, which works but feels really horrible: $itemId = substr(url(), strrpos(url(), '/') + 1);

It sounds like you are talking about the items/show.php page?

If that's right, this should do the trick

<?php $id =  metadata('item', 'id'); ?>