0

Drupal: 8.1.7

Module: token_filter 8.x-1.0-beta1

I have a custom block with a Text format that has Global and entity tokens are replaced with their values enabled.

The custom block has this value:

current-page:url:unaliased :          [current-page:url:unaliased]<br>
current-page:url:unaliased:absolute : [current-page:url:unaliased:absolute]<br>
current-page:url:unaliased:args :     [current-page:url:unaliased:args]<br>
current-page:url:unaliased:brief :    [current-page:url:unaliased:brief]<br>
current-page:url:unaliased:path :     [current-page:url:unaliased:path]<br>
current-page:url:unaliased:relative : [current-page:url:unaliased:relative]<br>

that will render as:

current-page:url:unaliased : http://www.example.com/node/1657
current-page:url:unaliased:absolute : http://www.example.com/node/1657
current-page:url:unaliased:args : , node, 1657
current-page:url:unaliased:brief : www.example.com/node/1657
current-page:url:unaliased:path : /node/1657
current-page:url:unaliased:relative : /node/1657

I am attempting to get the Content Id (e.g. [node:nid]) from the page, but that token is not available.

Workaround using Inline Javascript:

Node Id:

<script type="text/javascript">
<!-- language: lang-js -->
document.write("[current-page:url:unaliased:relative]".match(/\/node\/(\d+)/)[1])
</script>

which will render as:

Node Id: 1657

I tried the following:

current-page:url:unaliased:args:node : [current-page:url:unaliased:args:node]
current-page:url:unaliased:args:0 : [current-page:url:unaliased:args:1]
current-page:url:unaliased:args:1 : [current-page:url:unaliased:args:1]
current-page:url:unaliased:value:node : [current-page:url:unaliased:value:0]
current-page:url:unaliased:value:0 : [current-page:url:unaliased:value:0]
current-page:url:unaliased:value:1 : [current-page:url:unaliased:value:1]

Without modifying the module how would I get [node:nid] from within a Custom block?

0

[current-page:url:unaliased:args:value:1]

gives you the [node:nid] even when called from a block.

As per:

https://www.drupal.org/node/1265010

..."[current-page:url:unaliased:args:value:0] (The first value, of the array of arguments, of the unaliased URL of the current page)."

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.