0

Try to format that code in twig format:

<textarea class="form-control" name="email_review_subject_<?php echo $language['language_id']; ?>" ><?php echo isset(${'email_review_subject_' . $language['language_id']}) ? ${'email_review_subject_' . $language['language_id']} : ''; ?></textarea>

So i tried with that format:

<textarea class="form-control" name="email_review_subject_{{ language['language_id'] }}" >{{ isset({'email_review_subject_' . language.language_id}) ? {'email_review_subject_' . language.language_id} : '' }}</textarea>

Error:

Uncaught exception 'Twig_Error_Syntax' with message 'A hash key must be followed by a colon (:). Unexpected token "punctuation" of value "." ("punctuation" expected with value ":")

MorganFreeFarm
  • 3,811
  • 8
  • 23
  • 46

2 Answers2

3

I am pretty sure you can't use . to concatenate strings in Twig. Try ~, and look here: How to concatenate strings in twig

Ynhockey
  • 3,845
  • 5
  • 33
  • 51
  • Have you replaced both concatenations in your code? If so, this error is unlikely because it specifically tells you that you have a period (`.`). If that fails, it might be a problem with using dynamic variable names. Try the attribute function: https://twig.symfony.com/doc/2.x/functions/attribute.html – Ynhockey Nov 15 '17 at 16:03
  • I think the problem is here "(${" – MorganFreeFarm Nov 15 '17 at 16:06
3

There is no such thing as isset in twig. You also need to access the special variable _context if you want use dynamic variables in twig

Some possible solutions,

<textarea class="form-control" name="email_review_subject_{{ language['language_id'] }}" >{{ attribute(_context, 'email_review_subject_'~language.language_id)|default('') }}</textarea>

<textarea class="form-control" name="email_review_subject_{{ language['language_id'] }}" >{{ attribute(_context, 'email_review_subject_'~language.language_id) is defined ? attribute(_context, 'email_review_subject_'~language.language_id) : '' }}</textarea>

fiddle

TRiG
  • 10,148
  • 7
  • 57
  • 107
DarkBee
  • 16,592
  • 6
  • 46
  • 58