FORSMILE
JA
Smarty2016/02/09

[Smarty] Investigating Template Variables and Arrays

When I first entered the smartphone game development field, I only knew HTML, CSS, and JavaScript.

Back to Blog

When I first entered the smartphone game development field, I only knew HTML, CSS, and JavaScript.

It was a game developed for Mobage, which used PHP's CodeIgniter as its framework and Smarty as its template engine.

Smarty was completely new to me, so I initially worked while asking various questions to the other engineers.

This time, I'd like to briefly introduce the Smarty functionalities I commonly use.

INVESTIGATING VARIABLE AND ARRAY VALUES PASSED TO TEMPLATES

This is how to check if variables are being passed to the template file.

javascript
{$arena_rank|var_dump}

In the example above, for the variable named `arena_rank`, its value will be displayed at the location where it's written in the template.

With Smarty, you can also write it like the following. The display format is slightly different.

javascript
<div style="text-align:left;">{$areaList|@debug_print_var}</div>

It's enclosed in a `div` to make it easier to view in the browser when displayed. It's perfectly fine without it.

css
{DEBUG}

The functionality to display output in a separate window can also be configured to be always visible via PHP settings.

Recommended Smarty Books

There are only older books for Smarty, and only Kindle versions were available, but the following is recommended for beginners.

📦
Amazon で関連書籍・ツールを検索
PHP template engine development
Amazonで探す →(アソシエイトリンク)