How is it that it turns out? Returns wrong output if use it as array-key.

Created on 21 July 2022, over 2 years ago
Updated 26 July 2024, 4 months ago
{% set myIP = '[myIP]' %} {# [myIP]|[current-user:ip-address] #}
{% set myIP2 = drupal_token('current-user:ip-address') %}
{{ dump(myIP) }}/{{ dump(myIP2) }}

output

string(6) "23.106.56.12" /string(12) "23.106.56.12"

As a result (hostname: 23.106.56.12 is other field in views-watchdog; My-current-IP is 23.106.56.12)

Use drupal_token

{% set hostname = hostname|striptags|trim %}
{% set myIP2 = drupal_token('current-user:ip-address') %}
{{ dump(myIP2) }} //string(12) "23.106.56.12" 
{% set ourIPs = { (myIP2):'myIPAddress' } %}
({{ ourIPs[hostname] }}) // output (myIPAddress)

Use views_mailmerge_field

{% set hostname = hostname|striptags|trim %}
{% set myIP = '[myIP]' %} {# [myIP]|[current-user:ip-address] #}
{{ dump(myIP) }} //string(6) "23.106.56.12" 
{% set ourIPs = { (myIP):'myIPAddress' } %}
({{ ourIPs[hostname] }}) // output ()

In both cases {{ dump(ourIPs) }} returns

array(1) {
["23.106.56.12"]=>
string(4) "myIP2\myIP"
}

πŸ› Bug report
Status

Closed: cannot reproduce

Version

1.2

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States bwong

    What is myIP in the view? The dump with //string(6) "23.106.56.12" result seems odd. It could be something to do how Twig is handling a non-string value.

  • Status changed to Closed: cannot reproduce 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States bwong
Production build 0.71.5 2024