How to concat two variable values in template toolkit

61 views Asked by At

I am working on concat in template toolkit but currently i am facing issues. In my program i have defined a MACRO which has switch case and i have case value which is taken from multiple variable. please find the sample code

[%- MACRO get_seq(seq) BLOCK %]
[% SWITCH seq -%]
[% CASE '000' -%]
apply seq_0
[% CASE '001' -%]
apply seq_1
[% CASE '010' -%]
apply seq_2
[% CASE '011' -%]
apply seq_3
[% CASE '100' -%]
apply seq_4
[% CASE '101' -%]
apply seq_5
[% CASE '110' -%]
apply seq_6
[% CASE '111' -%]
apply seq_7
[% CASE  -%]
apply seq_z
[% END %]
[% END %]

[% set data1 = '11110000' %]
[% data2 = data1.split('') %]
[% get_seq(data2.7_data2.6_data2.5) %] // Needed get_seq(111)

How to concat 7 bit 6 bit 5 bit of data2?

1

There are 1 answers

0
clscott On

TT2 needs space around the concat operator:

[% get_seq(data2.7 _ data2.6 _ data2.5) %]

You might also want to consider an approach like this to avoid the concat:

[% data1 = '11110000' %]
[% data2 = data1.split('').slice(5,3).reverse.join('') %]
[% get_seq(data2) %]

To simplify the logic of calling the MACRO you may want to consider including the extraction of seq from the string in the MACRO definition.