Skip to content

Latest commit

 

History

History
210 lines (142 loc) · 6.35 KB

tutorial-3.md

File metadata and controls

210 lines (142 loc) · 6.35 KB
layout title
default
Try transferring variable to screen

{{ page.title }}

TTwig structure and View variable

  • In the previous chapter, I conducted Controller and creating/rendering Twig

  • In oder to build WEB Application,you need to transfer info from Controller to View. In this chapter,just use the basic parts.

Menu of this chapter

  • In this chapter, conduct the following part

    1. Explain about defining View variable for Controller

    2. Explain how to transfer variable when rendering Controller

    3. Explain how to display varible that received from Controller by Twig

Mofication Controller

  • Define variable in Controller,give variable that defined already in method [render] as parameter by associative array

  • In this time,「key」 becomes the optional character string,but when call variable in Twig side, it becomes the name

  • Modify CrudController.php as below quickly

    • /src/Eccube/Controller/Tutorial/CrudController.php
<script src="http://gist-it.appspot.com/https://github.com/EC-CUBE/ec-cube.github.io/blob/master/Source/tutorial_3/CrudController_add_var.php"></script>
  • Eplain the modification

    1. If transfer associative array for the second paramter of render method, you will be able to operate variable that transferred in twig. In this time, based on key of associative array to conduct operation of variable

    2. Key of associative array is optional.

Modify Twig

  • Add the display of variable that transferred by associative array in Controller, into Twig

  • Modify as below

    • Tutorial/crud_top.twig
<script src="http://gist-it.appspot.com/https://github.com/EC-CUBE/ec-cube.github.io/blob/master/Source/tutorial_3/crud_top_add_var.twig"></script>
  • Explain simply about the addition contents of this time

    1. Display variable that set in {{}}Twig by Controller

    2. There are 3 kinds of block(1.の{{}}) of Twig


      | ブロック種別 | 適用対象 | 凡例 | |------|------| | {{}} | 変数の中身を表示 | {{ viewstr|nl2b }} | | {%%} | ブロック内でロジックを記述する | {% if myvar is ... %} | | {##} | コメントアウト | {# DB取得内容を表示... #} |


    3. Use separately 3 kinds above in order to structure View

Confirm the display contents

  • Try accessing into Browser to confirm finally

    1. Please input「http://[ドメイン + インストールディレクトリ]/tutorial/crud」in URL of browser

    2. Contents of variable that defined in Controller, is displayed.


View変数のレンダリング


Collect this chapter

  • In this chapter, I studied the following part

    1. I explained how to add View variable to render method in Controller

    2. I conducted the display of varible of Twig

    3. I explained kind of Block of Twig

Global variable of View

  • The following variable has been intialized by 「Application.php」, storing, so you can call directly from all Twigs
変数名 詳細情報
BaseInfo 管理画面 > 設定 > 基本情報設定 > ショップマスターで保存した内容
title ページタイトル
  • About the call method will make call as below.

例. {{ BaseInfo.カラム名 }}

  • About the detail Twig structure, I will explain in next chapter

Reference

EC-CUBE 3のTwigのタグ覚え書き(一部EC-CUBE2系のSmarty比較)