Mario G. Lucas
Mario G. Lucas

Reputation: 1

Replace for URL not found in twig

I am trying to delete some part of my url (string) in twig, and I can not do it. The result is not that I expect:

"http://local.myurl.com/en/node/8"|replace("en/node/8", "")

I expect:

"http://local.myurl.com/"

And the result is:

"http://local.myurl.com/en/node/8"

Upvotes: 0

Views: 180

Answers (1)

doydoy44
doydoy44

Reputation: 5782

You can try json format like this :

{% set url = "http://local.myurl.com/en/node/8" %}
{{ url|replace({"en/node/8" : ""}) }}

Upvotes: 2

Related Questions