# Function that can show the data from database to the twig file

**URL:** https://discourse.slimframework.com/t/function-that-can-show-the-data-from-database-to-the-twig-file/1597
**Category:** Questions
**Created:** [June 21, 2017, 8:22am UTC](https://discourse.slimframework.com/t/function-that-can-show-the-data-from-database-to-the-twig-file/1597 "2017-06-21T08:22:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![shean10](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/shean10/32/431_2.png) [@shean10](https://discourse.slimframework.com/u/shean10)
#### Post date: [June 21, 2017, 8:22am UTC](https://discourse.slimframework.com/t/function-that-can-show-the-data-from-database-to-the-twig-file/1597/1 "2017-06-21T08:22:15Z")

</div>

I want to create a view that can show all the data from my database.

This is my function. How can I connect this to my twig file?  
 ![](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/1X/93e494297762d7dafffc80d2ab2b419987f78771.png)

Can anyone help 😥

Best regards.

---

<div class="post-metadata">

### Author: ![damianopetrungaro](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/damianopetrungaro/32/236_2.png) [@damianopetrungaro](https://discourse.slimframework.com/u/damianopetrungaro)
#### Post date: [June 21, 2017, 10:12am UTC](https://discourse.slimframework.com/t/function-that-can-show-the-data-from-database-to-the-twig-file/1597/2 "2017-06-21T10:12:59Z")

</div>

What does not works?

If you need a template engine you can use the twig by Symfony  
[Twig initialization in Slim (always into the container)](https://www.slimframework.com/docs/features/templates.html).

Anyway i suggest you to see the documentation (container section) for a better approach to the db initialization.

[Example of db connection initialization](https://github.com/damianopetrungaro/clean-architecture/blob/master/examples/slim/bootstrap/container.php#L55-L69) in the container
