1

Trying to use some Twig variables (simple strings) in a template that I created from a custom module. Using the Devel and Kint modules I can see the info under Iterator contents with:

{{kint(transaction[0])}}

enter image description here

I just can't get the template to print it out on the page.

I tried this:

<b>$ {{transaction.amount }}</b> total donation<br/><br/>

and

<b>$ {{transaction[0].amount }}</b> total donation<br/><br/>

Either way comes up empty. Not sure what I'm missing here. It works in other modules just fine. Maybe I'm too high on the Twig templates? I don't understand the tree structure very well. I created a template called transaction.html.twig.

This is what my controller looks like.

enter image description here

This is the .module file. It's passing over from the controller to this theme which then passes it to the twig file. At least this is how all the tutorials tell me to do it. I create this same thing on another module and it works fine.

function touchdownclub_theme($existing, $type, $theme, $path) {

 return array(
    'touchdownclubtransaction' => array(
      'variables' => array(
        'transaction' => NULL,
      ),
       'template' => 'touchdownclubtransaction',
    ),
  );
}
  • 1
    When you used {{kint(transaction[0])}} was it inside transaction.html.twig? – Matt Jan 16 '19 at 21:02
  • Is this a database query result? – Kevin Jan 16 '19 at 21:20
  • Is it also empty when you do {{ kint(transaction[0].value) }} ? – No Sssweat Jan 16 '19 at 21:23
  • This looks like an excecuted DB Statement object, try using {{ transaction[0].fetchCol(0) }} where 0 = first column (amount_per_touchdown?) and 1 is second column... – CG Monroe Jan 16 '19 at 21:44
  • Yes. {{kint(transaction[0])}} is inside transaction.html.twig – Tyler Jan 16 '19 at 21:46
0

I looked at some other modules controllers and saw that in the controller they used

$result = db_query    
$output = $result->fetchAll();

Before pushing the code to the return array. I tried it and it worked for me like it should. Problem solved.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.