access an array by its index?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamie
    Senior Member
    • Aug 2025
    • 172

    #1

    access an array by its index?

    i am trying to access an array directly by its index, and i can't find the right syntax, i believe it should be something like

    Code:
    {{#each cOADespatchDates}}
    {{this}} = {{cOaWrs.[@index]}}
    {{@index}}
    {{/each}}
    but this is giving me no joy

    if this isn't possible, can i somehow store the array by setting the key value, for example

    $array['myKey'] = 'someValue';

    yuri, your wisdom would be greatly appreciated here
  • yuri
    EspoCRM product developer
    • Mar 2014
    • 9532

    #2
    Lookup helper can be used: https://docs.espocrm.com/user-guide/...to-pdf/#lookup
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • jamie
      Senior Member
      • Aug 2025
      • 172

      #3
      Originally posted by yuri
      None of the options is working for me

      the data
      Click image for larger version

Name:	image.png
Views:	0
Size:	2.9 KB
ID:	123339
      Click image for larger version

Name:	image.png
Views:	0
Size:	3.2 KB
ID:	123337

      the code

      Code:
      {{#each cOADespatchDates}}
      {{this}} : {{lookup cOaWrs index}}
      {{this}} : {{lookup cOaWrs @index}}
      {{this}} : {{lookup cOaWrs key}}
      {{this}} : {{lookup cOaWrs @key}}
      {{this}} : {{cOaWrs.[key]}}
      {{this}} : {{cOaWrs.[@key]}}
      {{this}} : {{cOaWrs.[index]}}
      {{this}} : {{cOaWrs.[@index]}}
      {{@index}}
      {{/each}}​
      the output
      Click image for larger version

Name:	image.png
Views:	0
Size:	3.6 KB
ID:	123338

      yuri, what am I doing wrong? ​​

      Comment

      • heint
        Member
        • Jun 2025
        • 50

        #4
        jamie, Try to change the scope level inside the #each block so you will get access to the parent scope instead.

        something like this:
        Code:
        {{this}} : {{lookup ../cOaWrs index}}

        Comment

        • jamie
          Senior Member
          • Aug 2025
          • 172

          #5
          Originally posted by heint
          jamie, Try to change the scope level inside the #each block so you will get access to the parent scope instead.

          something like this:
          Code:
          {{this}} : {{lookup ../cOaWrs index}}
          wow thaks so much that works !!!! how did you figure that out?

          Comment

          Working...