Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Diogo Ribeiro
Diogo Ribeiro
17,343 Points

PHP - How to send data from the database to a TWIG files?

I have one index.php file and some templates (twig files). I'm trying to send some variables that I got from the database to the twig file and print them to the screen. The problem is that I don't know where to create the variables (probably on index.php) and how can I send them to the twig file.

1 Answer

Vince Brown
Vince Brown
16,249 Points

Hey Diogo, Php is not my strong suit, but I believe you could just put your data logic and all variables in your index.php(or any file)

Then at the top of your twig template include the file so your templates with have access to the data and variables.

<?php
   require_once('path/to/index.php');
?>