Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

I've started working on a new project that runs on Google's App Engine. I'm using PHP in the standard environment and for my templating engine I've decided on Smarty since that's something I've used in the past and was familiar with. It's not the cool new templating engine like Twig but it gets the job done and can be made to work on App Engine pretty easily.

So to start, the easiest way to get Smarty into your project is to add it to the composer.json file like so:
"require" : {
"smarty/smarty" : "^3.1"

Afterwards follow the usual steps for adding a new dependency with Composer. I've written a separate article about that here.

Then create a file called php.ini in your applications directory at the same location as your app.yaml file. Add the following contents to that file:
allow_url_include = "1"
google_app_engine.allow_include_gs_buckets = "#default#"

What the above does is instruct App Engine to allow cached template files to be included in your app from the Cloud DataStore.

In your application code, initialise Smarty like so:
$smarty = new \Smarty();
->setTemplateDir(__DIR__ . '/templates')
->setConfigDir(__DIR__ . '/templates')

The above assumes you have a 'templates' directory with your .tpl files. The compiled templates will be stored in the default bucket in the Cloud DataStore.

Now you can use Smarty as usual.


Skip down to comments...
Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...