Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How use wordpress and php function in twig? #176

Open
hamedmoody opened this issue Feb 17, 2017 · 6 comments
Open

How use wordpress and php function in twig? #176

hamedmoody opened this issue Feb 17, 2017 · 6 comments

Comments

@hamedmoody
Copy link

Hi.
How use wordpress and php functions in twig template.
Thanks for your best framework.

@ken-bem
Copy link

ken-bem commented Feb 17, 2017

You should google the Timber Framework

@hamedmoody
Copy link
Author

but i need herbert framework, is not any way?

@ken-bem
Copy link

ken-bem commented Feb 17, 2017

You use both, Timber is an addon for twig specifically for Wordpress

@hamedmoody
Copy link
Author

id use "composer require timber/timber". but what i do next?

@ken-bem
Copy link

ken-bem commented Feb 17, 2017

After that create a 'views' folder inside your app folder.

then you render using this code:

use Timber\Timber;

...
$context = Timber::get_context();

$context['VARIABLE_TO_ASSIGN_TO_TWIG'] = "foo";

Timber::render("path/to/template.twig", $context);

@webstractions
Copy link

You can also use Twig's registerUndefinedFunctionCallback() without having to include Timber. There are some caveats though. Check out the documentation for defining undefined functions on the fly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants