I'm using a twig template for a custom block that have images to link to specific nodes. I actually have the node IDs, however generating a relative link doesn't always work. Some pages are using aliases like so 127.0.0.1/web/products and some are using nodes like 127.0.0.1/web/node/19 so using the same relative link doesn't always work. Note that my drupal instance is within a /web/ folder and not at just 127.0.0.1
My twig template looks like this
<div class="row columns">
{% for key, image in imageurl %}
<div class="large-4 medium-3 column">
<a href="./node/{{ nid[key] }}">
<img src="../sites/default/files/{{ image }}"/>
</a>
<div>
{{ block_title[key] }}
</div>
</div>
{% endfor %}
</div>
When it appears on 127.0.0.1/web/products the link is
http://127.0.0.1/web/node/15
When it appears on 127.0.0.1/web/node/19 the link is
http://127.0.0.1/web/node/node/9
The image has the same issue, since 'image' only contains the filename. Is there a way I can automatically generate a link based on a node ID and a file that I know the path to, to account for URLs that may contain aliases?