You can use the following node setup instead of the UV trick:
Then you can use the Attribute node in the shader editor using the stored named attribute: