{"action":"created","issue":{"url":"https://api.github.com/repos/jarednova/timber/issues/513","repository_url":"https://api.github.com/repos/jarednova/timber","labels_url":"https://api.github.com/repos/jarednova/timber/issues/513/labels{/name}","comments_url":"https://api.github.com/repos/jarednova/timber/issues/513/comments","events_url":"https://api.github.com/repos/jarednova/timber/issues/513/events","html_url":"https://github.com/jarednova/timber/issues/513","id":65531707,"number":513,"title":"Timber::get_posts inside of twig file","user":{"login":"TristanSlater","id":1631008,"avatar_url":"https://avatars.githubusercontent.com/u/1631008?v=3","gravatar_id":"","url":"https://api.github.com/users/TristanSlater","html_url":"https://github.com/TristanSlater","followers_url":"https://api.github.com/users/TristanSlater/followers","following_url":"https://api.github.com/users/TristanSlater/following{/other_user}","gists_url":"https://api.github.com/users/TristanSlater/gists{/gist_id}","starred_url":"https://api.github.com/users/TristanSlater/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TristanSlater/subscriptions","organizations_url":"https://api.github.com/users/TristanSlater/orgs","repos_url":"https://api.github.com/users/TristanSlater/repos","events_url":"https://api.github.com/users/TristanSlater/events{/privacy}","received_events_url":"https://api.github.com/users/TristanSlater/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jarednova/timber/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-31T19:48:42Z","updated_at":"2016-02-25T18:03:48Z","closed_at":"2016-02-25T12:17:30Z","body":"Is it possible to create a query within a twig file? In my case, I'd like to replace `posts` with a new query. For example:\r\n\r\n    {% set posts = Timber.get_posts('post_type=pages') %}\r\n\r\nThis is impossible in PHP, because I need to use `posts` in the twig file *before* I replace it. I could use something like `pages`, and loop through that, but then I can't use generic templates.\r\n\r\nIs this something Timber supports?\r\n\r\nThanks,\r\nTristan"},"comment":{"url":"https://api.github.com/repos/jarednova/timber/issues/comments/188906184","html_url":"https://github.com/jarednova/timber/issues/513#issuecomment-188906184","issue_url":"https://api.github.com/repos/jarednova/timber/issues/513","id":188906184,"user":{"login":"TristanSlater","id":1631008,"avatar_url":"https://avatars.githubusercontent.com/u/1631008?v=3","gravatar_id":"","url":"https://api.github.com/users/TristanSlater","html_url":"https://github.com/TristanSlater","followers_url":"https://api.github.com/users/TristanSlater/followers","following_url":"https://api.github.com/users/TristanSlater/following{/other_user}","gists_url":"https://api.github.com/users/TristanSlater/gists{/gist_id}","starred_url":"https://api.github.com/users/TristanSlater/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TristanSlater/subscriptions","organizations_url":"https://api.github.com/users/TristanSlater/orgs","repos_url":"https://api.github.com/users/TristanSlater/repos","events_url":"https://api.github.com/users/TristanSlater/events{/privacy}","received_events_url":"https://api.github.com/users/TristanSlater/received_events","type":"User","site_admin":false},"created_at":"2016-02-25T18:03:47Z","updated_at":"2016-02-25T18:03:47Z","body":"Thanks. Adding it to the Twig file is fine.\n\nThe one thing I still find tricky though is when you have nested child\nposts inside posts. Right now, I just get the parent posts and then loop\nthrough the posts array and get the child posts for each one and add them\nto the array in the PHP file. Then I use nested loops again in the Twig,\nbut this seems really inefficient. Is there a way to get child posts with a\nquery?\n\nOn Thu, Feb 25, 2016 at 4:17 AM, Connor Burton <notifications@github.com>\nwrote:\n\n> Hi @TristanSlater <https://github.com/TristanSlater>, sorry for delayed\n> reply. I think adding via the context in PHP is the preferred way to be\n> honest.\n>\n> If you really wanted to do it the way above, on the next Timber release\n> you should be able to do the following (though not tested)\n>\n> TimberHelper::function_wrapper(array('Timber', 'get_posts'));\n>\n> Then you'd be able to do\n>\n> {% set posts = get_posts('post_type=pages') %}\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/jarednova/timber/issues/513#issuecomment-188757873>.\n>\n"}}