For your information, while the PHP side configures what values are passed to the template, this article focuses solely on how Smarty is handled within the template from a front-end perspective.
DISPLAYING VARIABLES PASSED TO THE TEMPLATE
If you have a variable named `arena_rank`, you just need to prefix it with `$` and enclose it in curly braces `{}` as shown below. This will display the value in the template:
ランキング {$arena_rank} 位DISPLAYING ARRAYS PASSED TO THE TEMPLATE
First, inspect the data using what's equivalent to PHP's `var_dump`.
For more details, please refer to [Smarty] Investigating Template Variables and Arrays.
<div style="text-align:left;">{$rank_list|@debug_print_var}</div>If we check the contents using `debug_print_var`, which we introduced recently, let's assume the `$rank_list` variable contained the following:
0
"山田"
1
"田中"
2
"中山"In the example above, if you want to display, for instance, the very first item "Yamada", you would do it as follows:
{$rank_list[0]}
{$rank_list.0}name
"山田"
mail
"aaa@aaa.com"
tel
"000-0000-0000"{$user.mail}{$rank_list.$arena_rank}The displayed name will change depending on the value of `arena_rank`.
Recommended Smarty Books
While Smarty only has older books, and only Kindle editions were available, the following is recommended for beginners.
📦