I have a custom block where I need to reference a URL relative to the current page (such as node/7/images or node/293/images) that will link to the "Images" view mode I made for the node. I am using a module so that a view mode is accessible via URL (which I have as node/#/images), but I am having trouble getting a working link to /images that would work on any given node.

I have tried to link it to /images and /#/images but have gotten a 404 each time, likely because it is going to example.com/images or example.com/#/images. I have also tried using the Token for current page URL which 404'd as well.

Is there a way, hopefully through the UI, in which I can reference the current node in a way that on any given node the link to the "Images" view mode will link to /node/[current node #]/images?

I have seen ways to implement it using custom modules or code, but I am not very experienced with putting custom code into Drupal and prefer to use the UI is possible.


I briefly had a fix, but then I broke it. I had got it working adding a link that referenced "images/" (without the quotations). While viewing the node, the custom block originally linked to example.com/node/#/images as intended.

However, I then configured the block to be hidden on */images (wasn't necessary to link to the view while viewing it). After I did this, the link broke on the node page, instead now referencing to example.com/node/images, missing the node # in the URL. I have no idea how this got broken as I only worked through the UI

I tried deleting the block then adding it again with no effect

Using "#/images" will direct to /node/123#/images (adding the actual # into the URL) - while this gets the current node id into the URL it doesnt work with the presence of the # symbol

1 Answer 1


Adding a relative path (without the starting "/") is WRT the current "directory", so when you're on a node page the "directory" is "node" and the NID is the "page". Your "images" is supposed to be another page within the same "directory". That's the simplified explanations about how relative paths work in general.

To solve your problem the easiest way is probably through a Token. Do you have Token Filter or a similar module installed and configured? If your Text format doesn't evaluate tokens you won't get the correct output.

Try some available tokens in your text and see what they output. Maybe there's a [current:path] or similar token, or [current:nid]. When you find one with the output you like you can contruct the link:

<a href="/node/[current:nid]/images">Images</a>


<a href="/[current:path]/images">Images</a>

If you need more control over the Block Visibility you can try Block Exclude Pages.

Another way to create contextually aware links is through Views (Block display). You would have a Node ID as the contextual filter, and override the Link to content field to add "/images" at the end of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.