Template logic to address a third URL segment
I would suggest you look into using Craft's Advanced Routing functionality to accomplish this.

For instance, add the following to your config/routes.php:

'stories/&lt;slug:\w+&gt;/?&lt;option:\w+&gt;?' =&gt; ['template' =&gt; '_extract'],


This will then populate the _extract template with the twig variable {{ slug }} and also the {{ option }} variable, if it exists.

Then in your twig template you can grab the entry and check for the existence of the option variable thus:

    {% set entry = craft.entries.section('stories').slug(slug).one() %}

    {% if entry %}
            &lt;h1&gt;Entry title is: {{ entry.title }}&lt;/h1&gt;
    {% endif %}

    &lt;h2&gt;Slug is: {{ slug }} &lt;/h2&gt;

    {% if option is defined %}
            &lt;h3&gt;Option is: {{ option }}&lt;/h3&gt;
    {% endif %}


I'd recommend reading the docs on Advanced routing as it's quite a powerful feature: https://docs.craftcms.com/v3/routing.html#advanced-routing