質問するログイン新規登録

回答編集履歴

2

コード追記

2017/10/31 06:08

投稿

aro10
aro10

スコア4106

answer CHANGED
@@ -1,4 +1,44 @@
1
1
  Twigでも以下ドキュメントにより、テンプレート内でTwig用のfor構文にて変数に対して繰り返し処理ができるので確認してみてください
2
2
  [Twig Documentation for](https://twig.symfony.com/doc/2.x/tags/for.html)
3
3
  [PHPでWebアプリ開発!人気テンプレートエンジン「Twig」を使ってみよう ](https://www.webprofessional.jp/twig-popular-stand-alone-php-template-engine/)
4
- [[PHP]Twigテンプレートの実践的な構成と作り方](https://php-archive.net/php/twig-advanced/)
4
+ [[PHP]Twigテンプレートの実践的な構成と作り方](https://php-archive.net/php/twig-advanced/)
5
+
6
+ [追記]
7
+ 公式のBasic API Usageをベースですが、HTMLタグ付きの二次元配列を処理して出力するサンプルコードです。
8
+ [Twig Introduction](https://twig.symfony.com/doc/2.x/intro.html)
9
+ ```
10
+ <?php
11
+ require_once './vendor/autoload.php';
12
+
13
+ $lists = [
14
+ [
15
+ "<li>test1</li>",
16
+ "<li>test2</li>",
17
+ "<li>test3</li>",
18
+ ],
19
+ [
20
+ "<li>test4</li>",
21
+ "<li>test5</li>",
22
+ "<li>test6</li>",
23
+ ],
24
+ ];
25
+ $template = <<< HTML
26
+ {% for list in lists %}
27
+ <ul>
28
+ {% for elm in list %}
29
+ {{ elm|raw }}
30
+ {% endfor %}
31
+ </ul>
32
+ {% endfor %}
33
+
34
+ HTML;
35
+ $loader = new Twig_Loader_Array(array(
36
+ 'index' => $template,
37
+
38
+ ));
39
+ $twig = new Twig_Environment($loader);
40
+ echo $twig->render('index', array('lists' => $lists));
41
+ ```
42
+
43
+ Twigはマニュアルが整備されており、一度機能全体を読んでみてください。
44
+ [Twig Documentation](https://twig.symfony.com/doc/2.x/)

1

参考追記

2017/10/31 06:08

投稿

aro10
aro10

スコア4106

answer CHANGED
@@ -1,2 +1,4 @@
1
1
  Twigでも以下ドキュメントにより、テンプレート内でTwig用のfor構文にて変数に対して繰り返し処理ができるので確認してみてください
2
- [Twig Documentation for](https://twig.symfony.com/doc/2.x/tags/for.html)
2
+ [Twig Documentation for](https://twig.symfony.com/doc/2.x/tags/for.html)
3
+ [PHPでWebアプリ開発!人気テンプレートエンジン「Twig」を使ってみよう ](https://www.webprofessional.jp/twig-popular-stand-alone-php-template-engine/)
4
+ [[PHP]Twigテンプレートの実践的な構成と作り方](https://php-archive.net/php/twig-advanced/)