前提・実現したいこと
PHPテンプレートエンジン「smarty」に関して
質問です。smartyのif文の問題になります。
if文を用いて、下記の記載された条件で振り分けて表示するには
どうしたら良いでしょうか?
未経験からフロントエンジニアとして働いています。
プログラミング学習はまだまだ全然不足しており、
下記の課題も自力では解けず、恥を忍んでお聞きします。
どうぞよろしくお願いします。
【条件->表示内容】
3で割り切れる場合-> une
5で割り切れる場合-> deux
どちらでも割り切れる場合-> trois
それ以外-> そのままの数字
【解答用紙】
{section loop=$num name="num_loop"}
{$smarty.section.num_loop.index}
<br>
** {if}
{else}
{elseif}
{/if}**
{/section}
【出力結果】
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
【解答の理想像】
0
1
2
une
4
deux
Fizz
7
8
une
deux
11
une
13
14
trois
**### 試したこと
**
もっとも解答に近いコーディングは以下に載せています。
{section loop=$num name="num_loop"}
{$smarty.section.num_loop.index}
<br>
{if $smarty.section.num_loop.index_prev is div by 3}
<p>Fizz</p>
{/if}
{if $smarty.section.num_loop.index is div by 5}
<p>Buzz</p>
{/if}
{if $num_loop is div by 3 && $num_loop is div by 5}
<p>FizzBuzz</p>
{/if}
{/section}
【解答結果】
0
deux
trois
1
une
trois
2
trois
3
trois
4
une
trois
5
deux
trois
6
trois
7
une
trois
8
trois
9
trois
10
une
deux
trois
11
trois
12
trois
13
une
trois
14
trois
15
deux
trois

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。