The current page url is http://website/p1/p2/p3/p4.
In Drupal 8 twig, use function to get path p1/p2/p3/p4
{{ set site_path = path("<current>") }}
{{ site_path }}
The site_path is p1/p2/p3/p4.
How to get the element in the path, for example, the second p2