Forum Discussion

darrenSP's avatar
darrenSP
Mentor
7 years ago

Get all text keys

Hi,

Is it possible to get all text keys that match a certain criteria? For example, I have text keys like this:

key: category.instance.1
value: Category instance 1 text

key: category.instance.2
value: Category instance 2 text

key: category.instance.3
value: Category instance 3 text

I want to get these all in some sort of array and loop through them to use them in something.

Is it possible?

  • darrenSP's avatar
    darrenSP
    7 years ago

    Ahhh I thought that may be the case.

    I'm thinking of storing a count in a text property then looping based on that number. 

     

    <#assign count = text.format('category.count') />
    <#list 1..count?number as i>
      <#assign msg = text.format('category.instance.${i}') />
      ${msg}
    </#list>

3 Replies

  • darrenSP - You cannot get text key dynamically from the studio.  You must need a name of text key to use in the components.  

    If you know all the text key, you can create an array of that. 

    <#assign textKeys = ['key1', 'key2', 'key3'] />
    <#list textKeys as key >
      ${text.format(key)}
    </#list>
  • darrenSP's avatar
    darrenSP
    Mentor
    7 years ago

    Ahhh I thought that may be the case.

    I'm thinking of storing a count in a text property then looping based on that number. 

     

    <#assign count = text.format('category.count') />
    <#list 1..count?number as i>
      <#assign msg = text.format('category.instance.${i}') />
      ${msg}
    </#list>