0

I want to capture a value from the url and display it in a piece of content, if available. In my node body I enter text like:

The sid is "[current-page:query:sid]".

If I then view that node at http://example.org/node/123?sid=foo the content shows as:

The sid is "foo".

Excellent, all working great. Here's the problem: if I visit the page without the ?sid argument in the url (just going to /node/123), then the content displays literally as:

The sid is "[current-page:query:sid]".

I would prefer the token to just be blank in that case. How can I get it to output

The sid is "".

1 Answer 1

2

The reason for what you experiencing is the default behavior of token_replace() to leave tokens untouched if no replacement value was provided.

In your case, the Token Filter module would have to provide the option 'clear' => true when calling token_replace().

You may want to try to apply the patch in this issue to the token_filter module.

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.