Dynamic URLs on template page using slug as part of URL

On a template page, I’d like to have a button with a link that includes the slug, like so:

https://www.mydomain/collection-name/slug << How would I dynamically insert just the slug into that link?

Thanks!

You can access that and other URL attributes via javascript.

Here is a good source for review.

Thanks! And are the CMS attributes also available via javascript?