{"id":2678,"date":"2018-11-30T01:06:22","date_gmt":"2018-11-29T16:06:22","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=2678"},"modified":"2018-11-30T01:06:22","modified_gmt":"2018-11-29T16:06:22","slug":"%e7%b0%a1%e5%8d%98%ef%bc%81laravel%e3%81%a7twig%e3%83%86%e3%83%b3%e3%83%97%e3%83%ac%e3%83%bc%e3%83%88%e3%82%a8%e3%83%b3%e3%82%b8%e3%83%b3%e3%82%92%e4%bd%bf%e3%81%86%e5%ae%9f%e4%be%8b","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=2678","title":{"rendered":"\u7c21\u5358\uff01Laravel\u3067twig\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u3092\u4f7f\u3046\u5b9f\u4f8b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30a8\u30f3\u30b8\u30f3\u3068\u3044\u3048\u3070\u6709\u540d\u306aSmarty\u3084Laravel\u306b\u6a19\u6e96\u642d\u8f09\u3055\u308c\u3066\u3044\u308bBlade\u306a\u3069\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u3053\u3053\u6700\u8fd1PHP\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30a8\u30f3\u30b8\u30f3\u3067\u4eba\u6c17\u3092\u96c6\u3081\u3066\u3044\u308b\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u304c\u3001<a href=\"https:\/\/twig.symfony.com\/\" target=\"_blank\" rel=\"noopener\">Twig<\/a>\u3067\u3059\u3002<\/p>\n<p>\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u3092\u898b\u3066\u3082\u3089\u3048\u3070\u3068\u5206\u304b\u308b\u3068\u304a\u308a\u3001\u3053\u3061\u3089\u3082Blade\u3068\u540c\u3058\u304f\u30b7\u30f3\u30d7\u30eb\u304b\u3064\u9ad8\u6a5f\u80fd\u3092\u5b9f\u73fe\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u306a\u305cLaravel\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u306b<code>Twig<\/code>\u3092\u4f7f\u3046\u304b\u3068\u3044\u3046\u3068\u3001\u904e\u53bb\u306b\u4f5c\u3063\u305f\u30b3\u30fc\u30c9\u3092\u518d\u5229\u7528\u3059\u308b\u5834\u5408\u3084\u3001\u305d\u3082\u305d\u3082<code>Twig<\/code>\u306e\u65b9\u306b\u6163\u308c\u89aa\u3057\u3093\u3067\u3044\u3066\u4f7f\u3044\u3084\u3059\u3044\u306a\u3069\u306e\u7406\u7531\u3092\u60f3\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Laravel<\/code>\u3067<code>Twig<\/code>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30a8\u30f3\u30b8\u30f3\u3092\u4f7f\u3046\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<p>\u305c\u3072\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2597 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2.png\" alt=\"\" width=\"275\" height=\"350\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2.png 275w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2-236x300.png 236w\" sizes=\"auto, (max-width: 275px) 100vw, 275px\" \/><\/p>\n<p>\u203b \u5b9f\u884c\u74b0\u5883\uff1a Laravel 5.7<\/p>\n<h1>\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h1>\n<p><code>Laravel<\/code>\u3067<code>Twig<\/code>\u3092\u5229\u7528\u3059\u308b\u5c02\u7528\u30d1\u30c3\u30b1\u30fc\u30b8<a href=\"https:\/\/github.com\/rcrowe\/TwigBridge\" target=\"_blank\" rel=\"noopener\">rcrowe\/twigbridge<\/a>\u304c\u516c\u958b\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u3053\u308c\u3092<code>composer<\/code>\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>composer require rcrowe\/twigbridge<\/strong><\/pre>\n<p>Laravel 5.5\u4ee5\u4e0a\u3092\u4f7f\u3063\u3066\u3044\u308b\u5834\u5408\u306f<code>Auto-Discovery<\/code>\u304c\u3042\u308b\u306e\u3067\u3001\u3053\u308c\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u5b8c\u4e86\u3067\u3059\u304c\u3001\u305d\u308c\u4ee5\u524d\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u5834\u5408\u3060\u3068<code>config\/app.php<\/code>\u3067\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u767b\u9332\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre>'providers' =&gt; [\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>TwigBridge\\ServiceProvider::class,<\/strong>\r\n],<\/pre>\n<pre>'aliases' =&gt; [\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>'Twig' =&gt; TwigBridge\\Facade\\Twig::class,<\/strong>\r\n],<\/pre>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b<code>Twig<\/code>\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u3063\u3066\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h1>Twig\u3092\u5b9f\u884c\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f<code>twig<\/code>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092<code>Laravel<\/code>\u3067\u5b9f\u884c\u3059\u308b\u624b\u9806\u3092\u307f\u307e\u3057\u3087\u3046\u3002<span style=\"font-size: 1rem;\">\u30a2\u30af\u30bb\u30b9\u3059\u308b\u30da\u30fc\u30b8\u306f<\/span><code>http:\/\/example.test\/home<\/code><span style=\"font-size: 1rem;\">\u3067\u3059\u3002<\/span><\/p>\n<p>\u307e\u305a\u3001<code>resources\/views\/home.twig<\/code>\u3092\u4f5c\u6210\u3057\u3066\u4ee5\u4e0b\u306e\u5185\u5bb9\u3067\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>&lt;!-- home.twig --&gt;<\/strong>\r\n&lt;html&gt;\r\n    &lt;body&gt;\r\n        <strong>&lt;h1&gt;\u3053\u308c\u306f\u3001Twig\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u3059\u3002&lt;\/h1&gt;<\/strong>\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u6b21\u306b<code>routes\/web.php<\/code>\u3092\u958b\u3044\u3066\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>\/\/ web.php<\/strong>\r\n\r\nRoute::get('\/home', function(){\r\n\r\n    <strong>return view('home');<\/strong> \/\/ .twig\u306f\u4e0d\u8981\r\n\r\n});<\/pre>\n<p>\u3067\u306f\u5b9f\u969b\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2679\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_twig_1.png\" alt=\"\" width=\"441\" height=\"51\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_twig_1.png 441w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_twig_1-300x35.png 300w\" sizes=\"auto, (max-width: 441px) 100vw, 441px\" \/><\/p>\n<p>\u3053\u3053\u3067\u91cd\u8981\u306a\u306e\u304c\u3001\u6b21\u306e\u3088\u3046\u306b\u62e1\u5f35\u5b50\u4ee5\u5916\u304c\u540c\u3058\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u304c\uff12\u3064\u3042\u3063\u305f\u5834\u5408\u306f<code>twig<\/code>\u304c\u512a\u5148\u3055\u308c\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n<ul>\n<li>home.blade.php<\/li>\n<li>home.twig\u3000\u30fb\u30fb\u30fb\u3000\u512a\u5148<\/li>\n<\/ul>\n<p>\u3064\u307e\u308a\u3001\u3082\u3057\u4e0a\u8a18\u306e\u5834\u5408\u306btwig\u30d5\u30a1\u30a4\u30eb\u304c\u524a\u9664\u3055\u308c\u305f\u5834\u5408\u306f<code>home.blade.php<\/code>\u304c\u81ea\u52d5\u7684\u306b\u9069\u7528\u3055\u308c\u308b\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h1>Twig\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u5909\u6570\u3092\u9001\u308b<\/h1>\n<p><code>Twig<\/code>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3078\u5909\u6570\u3092\u9001\u308b\u5834\u5408\u3082\u3001<code>Blade<\/code>\u306e\u5834\u5408\u3068\u5909\u308f\u308a\u307e\u305b\u3093\u3002<br \/>\n\u5b9f\u969b\u306e\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u6587\u5b57\u5217\u306e\u5834\u5408<\/h2>\n<pre><strong>\/\/ routes\/web.php<\/strong>\r\n\r\nRoute::get('\/home', function(){\r\n\r\n    return view('home', <strong>[<\/strong>\r\n<strong>        'value' =&gt; 'xxx'<\/strong>\r\n<strong>    ]<\/strong>);\r\n\r\n});<\/pre>\n<pre><strong>&lt;!-- home.twig --&gt;<\/strong>\r\n&lt;html&gt;\r\n    &lt;body&gt;\r\n        <strong>{{ value }}<\/strong>\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2680\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_twig_2.png\" alt=\"\" width=\"42\" height=\"32\" \/><\/p>\n<h2>\u914d\u5217\u306e\u5834\u5408<\/h2>\n<pre><strong>\/*** routes\/web.php ***\/<\/strong>\r\n\r\nRoute::get('\/home', function(){\r\n\r\n    return view('home', <strong>[<\/strong>\r\n<strong>        'values' =&gt; ['yyy', 'zzz']<\/strong>\r\n<strong>    ]<\/strong>);\r\n\r\n});<\/pre>\n<pre><strong>&lt;!-- home.twig --&gt;<\/strong>\r\n&lt;html&gt;\r\n    &lt;body&gt;\r\n        <strong>{% for value in values %}<\/strong>\r\n<strong>            {{ value }}<\/strong>\r\n<strong>        {% endfor %}<\/strong>\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2681\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_twig_3.png\" alt=\"\" width=\"69\" height=\"24\" \/><\/p>\n<h1>config\u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u3063\u305f\u8a2d\u5b9a<\/h1>\n<p><code>rcrowe\/twigbridge<\/code>\u306b\u306f\u3001\u30b3\u30f3\u30d5\u30a3\u30b0\u30fb\u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u3063\u3066<code>twig<\/code>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u3088\u308a\u7d30\u304b\u306a\u8a2d\u5b9a\u3092\u3059\u308b\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u6a5f\u80fd\u3092\u4f7f\u3046\u305f\u3081\u306b\u306f\u3001\u307e\u305a\u4ee5\u4e0b\u306e<code>php artisan<\/code>\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3063\u3066<code>twigbridge.php<\/code>\u3092<code>Laravel<\/code>\u5074\u3078\u30b3\u30d4\u30fc\u3057\u307e\u3059\u3002<\/p>\n<pre>php artisan vendor:publish --provider=\"TwigBridge\\ServiceProvider\"<\/pre>\n<p>\u3053\u308c\u3067\u3001<code>config\/twigbridge.php<\/code>\u304c\u4f5c\u6210\u3055\u308c\u307e\u3057\u305f\u306e\u3067\u3001\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u5185\u3067\u69d8\u3005\u306a\u8a2d\u5b9a\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u8a2d\u5b9a\u5185\u5bb9\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<h2>twig\uff08\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u95a2\u3059\u308b\u8a2d\u5b9a\uff09<\/h2>\n<h3>extension<\/h3>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u9069\u7528\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u62e1\u5f35\u5b50\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001<strong>&#8220;tpl.php&#8221;<\/strong> \u3078\u5909\u66f4\u3057\u305f\u5834\u5408\u3001<code>****.tpl.php<\/code>\u304c\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3068\u3057\u3066\u9069\u7528\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>environment<\/h3>\n<h4>debug<\/h4>\n<p><code>true<\/code>\u306b\u3059\u308b\u3068\u3001twig\u5185\u3067<code>dump()<\/code>\u304c\u4f7f\u3048\u308b\u3088\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>{{ <strong>dump(values)<\/strong> }}<\/pre>\n<p>\u5b9f\u884c\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2682\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_twig_4.png\" alt=\"\" width=\"319\" height=\"77\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_twig_4.png 319w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_twig_4-300x72.png 300w\" sizes=\"auto, (max-width: 319px) 100vw, 319px\" \/><\/p>\n<h4>charset<\/h4>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u4f7f\u3046\u6587\u5b57\u30b3\u30fc\u30c9\u3067\u3059\u3002<br \/>\n\u7279\u5225\u306a\u7406\u7531\u304c\u306a\u3044\u5834\u5408\u4ee5\u5916\u306f\u3001\u57fa\u672c\u7684\u306b<strong> &#8220;utf-8&#8221;<\/strong> \u304c\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<h4>base_template_class<\/h4>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4f7f\u3046\u30af\u30e9\u30b9\u3002<br \/>\n\u521d\u671f\u72b6\u614b\u3067\u306f\u3001<code>TwigBridge<\/code>\u306e<code>Template.php<\/code>\uff08Twig\u672c\u4f53\u3092\u62e1\u5f35\u3057\u3066\u3044\u308b\u30af\u30e9\u30b9\uff09\u3092\u4f7f\u3046\u3053\u3068\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u72ec\u81ea\u306bTwig\u3092\u62e1\u5f35\u3057\u305f\u30af\u30e9\u30b9\u3092\u4f7f\u3046\u5834\u5408\u306f\u3053\u3053\u3067\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h4>cache<\/h4>\n<p><code>Twig<\/code>\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u3001\u521d\u671f\u72b6\u614b\u3067\u306f<code>storage\/views\/twig<\/code>\u5185\u306b\u4f5c\u6210\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u306e\u30d5\u30a9\u30eb\u30c0\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u3067\u3044\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001<code>storage\/twig<\/code>\u30d5\u30a9\u30eb\u30c0\uff08\u66f8\u304d\u8fbc\u307f\u6a29\u9650\u3092\u5fd8\u308c\u306a\u3044\u3067\u304f\u3060\u3055\u3044\uff09\u3092\u4f5c\u6210\u3057\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3068\u305d\u306e\u4e2d\u3078\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4fdd\u5b58\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><strong>'cache' =&gt; storage_path('twig'),<\/strong><\/pre>\n<h4>auto_reload<\/h4>\n<p>\u30ad\u30e3\u30c3\u30b7\u30e5\u30d5\u30a1\u30a4\u30eb\u3092\u5e38\u306b\u66f4\u65b0\u3059\u308b\u304b\u3069\u3046\u304b\u3092\u8a2d\u5b9a\u3059\u308b\u9805\u76ee\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u958b\u767a\u4e2d\u306f\u3088\u304f\u5185\u5bb9\u3092\u5909\u66f4\u3059\u308b\u305f\u3081<code>true<\/code>\u306b\u3057\u3066\u304a\u304d\u3001\u672c\u756a\u74b0\u5883\u306f<code>false<\/code>\u306b\u3059\u308b\u3053\u3068\u3067\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u4e0a\u3052\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<h4>strict_variables<\/h4>\n<p>\u4f8b\u3048\u3070\u3001<code>xxx<\/code>\u3068\u3044\u3046\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u306a\u3044\u5909\u6570\u304c\u4f7f\u308f\u308c\u305f\u3068\u304d\u306b\u30a8\u30e9\u30fc\uff08\u4f8b\u5916\uff09\u3092\u8868\u793a\u3059\u308b\u304b\u3069\u3046\u304b\u3068\u3044\u3046\u8a2d\u5b9a\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u5b9f\u969b\u306b\u3084\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>&lt;!-- home.twig --&gt;<\/strong>\r\n&lt;html&gt;\r\n    &lt;body&gt;\r\n\u3000\u3000\u3000\u3000\u3000<strong>&lt;!-- \u5b58\u5728\u3057\u306a\u3044\u5909\u6570 \"xxx\" \u3092\u4f7f\u3046 --&gt;<\/strong>\r\n        <strong>{{ xxx }}<\/strong>\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3082\u3057\u521d\u671f\u72b6\u614b<code>false<\/code>\u306e\u5834\u5408\u3001\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u306a\u3044\u5909\u6570\u304c\u4f7f\u308f\u308c\u3066\u3082\u30b9\u30ad\u30c3\u30d7\u3055\u308c\u3066\u30a8\u30e9\u30fc\u306f\u51fa\u307e\u305b\u3093\u304c\u3001<code>true<\/code>\u306e\u5834\u5408\u306f\u6b21\u306e\u3088\u3046\u306a\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2683\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_twig_5.png\" alt=\"\" width=\"410\" height=\"171\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_twig_5.png 410w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_twig_5-300x125.png 300w\" sizes=\"auto, (max-width: 410px) 100vw, 410px\" \/><\/p>\n<h4>autoescape<\/h4>\n<p>\u7279\u6b8a\u6587\u5b57\u3092\u30a8\u30b9\u30b1\u30fc\u30d7\u3059\u308b\u5f62\u5f0f\uff08\u3082\u3057\u304f\u306f\u3001\u3057\u306a\u3044\uff09\u3092\u8a2d\u5b9a\u3059\u308b\u9805\u76ee\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u6b21\u306e\u3088\u3046\u306a\u30c7\u30fc\u30bf\u3092<code>twig<\/code>\u3078\u9001\u4fe1\u3057\u3001<\/p>\n<pre><strong>\/\/ web.php<\/strong>\r\n\r\nreturn view('home', [\r\n    <strong>'value' =&gt; '&lt;test&gt;'<\/strong>\r\n]);<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u8868\u793a\u3059\u308b\u3068\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>&lt;!-- home.twig --&gt;<\/strong>\r\n&lt;html&gt;\r\n    &lt;body&gt;\r\n        <strong>{{ value }}<\/strong>\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3059\u308b\u3068HTML\u30b3\u30fc\u30c9\u306f\u6700\u7d42\u7684\u306b\u3053\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre>&lt;html&gt;\r\n    &lt;body&gt;\r\n        <strong>&amp;lt;<\/strong>test<strong>&amp;gt;<\/strong>\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u307e\u305f\u3053\u306e\u8a2d\u5b9a\u3067\u6b21\u306e\u3088\u3046\u306a\u30a8\u30b9\u30b1\u30fc\u30d7\u65b9\u6cd5\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<ul>\n<li>html\u3000\u30fb\u30fb\u30fb\u3000HTML\u7528\u30a8\u30b9\u30b1\u30fc\u30d7<\/li>\n<li>css\u3000\u30fb\u30fb\u30fb\u3000CSS\u7528\u30a8\u30b9\u30b1\u30fc\u30d7<\/li>\n<li>js\u3000\u30fb\u30fb\u30fb\u3000JavaScript\u7528\u30a8\u30b9\u30b1\u30fc\u30d7<\/li>\n<li>url\u3000\u30fb\u30fb\u30fb\u3000URL\u7528\u30a8\u30b9\u30b1\u30fc\u30d7<\/li>\n<li>html_attr\u3000\u30fb\u30fb\u30fb\u3000HTML\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u7528\u30a8\u30b9\u30b1\u30fc\u30d7<\/li>\n<\/ul>\n<p>\u307e\u305f\u3001\u72ec\u81ea\u306e\u30a8\u30b9\u30b1\u30fc\u30d7\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<br \/>\n\u305d\u306e\u5834\u5408\u306f\u307e\u305a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>app\/Providers\/AppServiceProvider.php<\/code>\u5185\u3067\u6b21\u306e\u3088\u3046\u306b\u72ec\u81ea\u306e\u30a8\u30b9\u30b1\u30fc\u30d7\u65b9\u6cd5\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre>public function boot()\r\n{\r\n    <strong>$this-&gt;app['twig']-&gt;getExtension('core')-&gt;setEscaper('replace_dot', function($environment, $string, $charset) {<\/strong>\r\n\r\n<strong>        return str_replace('.', '[dot]', $string);<\/strong>\r\n\r\n<strong>    });<\/strong>\r\n}<\/pre>\n<p>\u305d\u3057\u3066\u3001\u72ec\u81ea\u30a8\u30b9\u30b1\u30fc\u30d7\u540d\u3092\u6307\u5b9a\u3057\u3066\u3084\u308c\u3070\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre>'autoescape' =&gt; <strong>'replace_dot'<\/strong>,<\/pre>\n<p>\u3053\u308c\u3092\u5b9f\u884c\u3059\u308b\u3068 <strong>&#8220;example.com&#8221;<\/strong> \u3068\u3044\u3046\u6587\u5b57\u5217\u306f <strong>&#8220;example[dot]com&#8221;\u00a0<\/strong>\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4>optimizations<\/h4>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u969b\u306b\u6700\u9069\u5316\u3059\u308b\u65b9\u6cd5\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<br \/>\n\u6307\u5b9a\u3067\u304d\u308b\u65b9\u6cd5\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ul>\n<li>-1\u3000\u30fb\u30fb\u30fb\u3000\u5168\u3066\u306e\u6700\u9069\u5316\u3092\u5b9f\u884c\u3057\u307e\u3059\uff08OPTIMIZE_ALL\uff09<\/li>\n<li>0\u3000\u30fb\u30fb\u30fb\u3000\u6700\u9069\u5316\u3092\u3057\u307e\u305b\u3093\uff08OPTIMIZE_NONE\uff09<\/li>\n<li>2\u3000\u30fb\u30fb\u30fb\u3000\u53ef\u80fd\u306a\u9650\u308a<code>for<\/code>\u3092\u6700\u9069\u5316\u3057\u307e\u3059\uff08OPTIMIZE_FOR\uff09<\/li>\n<li>4\u3000\u30fb\u30fb\u30fb\u3000\u53ef\u80fd\u306a\u9650\u308a<code>raw<\/code>\u3092\u6700\u9069\u5316\u3057\u307e\u3059\uff08OPTIMIZE_FOR\uff09<\/li>\n<li>8\u3000\u30fb\u30fb\u30fb\u3000\u53ef\u80fd\u306a\u9650\u308a\u5909\u6570\u306e\u4f5c\u6210\u3068\u30a2\u30af\u30bb\u30b9\u3092\u5358\u7d14\u5316\u3057\u307e\u3059\uff08OPTIMIZE_VAR_ACCESS\uff09<\/li>\n<\/ul>\n<h4>globals<\/h4>\n<p>\u3069\u3053\u304b\u3089\u3067\u3082\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u5909\u6570\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u3001\u3053\u3053\u3078\u6b21\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3059\u308b\u3068\u3001<\/p>\n<pre><strong>\/\/ twigbridge.php<\/strong>\r\n\r\n'globals' =&gt; [\r\n    'wherever' =&gt; '\u3069\u3053\u304b\u3089\u3067\u3082\u30a2\u30af\u30bb\u30b9\u53ef\u80fd\u3067\u3059\uff01'\r\n],<\/pre>\n<p>\u7279\u306b\u5909\u6570\u3092\u6307\u5b9a\u3057\u306a\u304f\u3066\u3082\u3001\u3053\u306e\u3088\u3046\u306b<code>twig<\/code>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5185\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><strong>&lt;!-- home.twig --&gt;<\/strong>\r\n&lt;html&gt;\r\n    &lt;body&gt;\r\n        <strong>{{ wherever }}<\/strong>\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h2>extensions<\/h2>\n<p><code>Twig<\/code>\u306e\u62e1\u5f35\u3092\u6709\u52b9\u306b\u3059\u308b\u8a2d\u5b9a\u3067\u3059\u3002<\/p>\n<h2>facades<\/h2>\n<p>Laravel\u306eFacade\u3092Twig\u5185\u3067\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001<code>Config<\/code>\u3092\u4f7f\u3044\u305f\u3044\u5834\u5408\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>\/\/ twigbridge.php<\/strong>\r\n\r\n'facades' =&gt; [\r\n    <strong>'Config'<\/strong>\r\n],<\/pre>\n<pre><strong>&lt;!-- home.twig --&gt;<\/strong>\r\n&lt;html&gt;\r\n    &lt;body&gt;\r\n        <strong>{{ Config.get('app.name') }}<\/strong>\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h2>functions<\/h2>\n<p><code>Twig<\/code>\u5185\u3067\u4f7f\u3048\u308b\u95a2\u6570\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u521d\u671f\u72b6\u614b\u3067\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b<code>last()<\/code>\uff08\u914d\u5217\u306e\u6700\u5f8c\u306e\u8981\u7d20\u3092\u53d6\u5f97\u3059\u308b\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\uff09\u306e\u4f7f\u3044\u65b9\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>&lt;html&gt;\r\n    &lt;body&gt;\r\n        <strong>{{ last(values) }}<\/strong>\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u307e\u305f\u3001\u76f4\u63a5\u3053\u3053\u3067\u72ec\u81ea\u306e\u95a2\u6570\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<br \/>\n\u6b21\u306e\u4f8b\u306f\u6570\u5b57\u3092\uff13\u6841\u30ab\u30f3\u30de\u533a\u5207\u308a\u306b\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>'functions' =&gt; [\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>'number_format' =&gt; function($number) {<\/strong>\r\n\r\n<strong>        return number_format($number);<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n],<\/pre>\n<p>\u305d\u3057\u3066\u3001\u6b21\u306e\u3088\u3046\u306b\u3059\u308c\u3070\u6570\u5b57\u304c\uff13\u6841\u30ab\u30f3\u30de\u533a\u5207\u308a\u3067\u8868\u793a\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>&lt;html&gt;\r\n    &lt;body&gt;\r\n        <strong>{{ number_format(price) }}<\/strong>\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h2>filters<\/h2>\n<p>Twig\u3067\u5229\u7528\u3067\u304d\u308b\u30d5\u30a3\u30eb\u30bf\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u3001\u914d\u5217\u30c7\u30fc\u30bf\u3092JSON\u5316\u3059\u308b\u30d5\u30a3\u30eb\u30bf\u30fc\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u30d5\u30a3\u30eb\u30bf\u30fc\u306bPHP\u6a19\u6e96\u95a2\u6570\u306e<code>json_encode()<\/code>\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre>'filters' =&gt; [\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>'json' =&gt; 'json_encode'<\/strong>\r\n],<\/pre>\n<p>\u3059\u308b\u3068\u3001\u6b21\u306e\u3088\u3046\u306a\u3059\u308b\u3060\u3051\u3067<code>json_encode()<\/code>\u304c\u9069\u7528\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>&lt;html&gt;\r\n    &lt;body&gt;\r\n        <strong>{{ values | json }}<\/strong>\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u5b9f\u969b\u306b\u5b9f\u884c\u3057\u305f\u4f8b\u3067\u3059\u3002<\/p>\n<pre>[\"yyy\",\"zzz\"]<\/pre>\n<p>\u306a\u304a\u3001\u6b21\u306e\u3088\u3046\u306b\u76f4\u63a5\u95a2\u6570\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>'replace_dot' =&gt; <strong>function($value) {<\/strong>\r\n\r\n<strong>    return str_replace('.', '[dot]', $value);<\/strong>\r\n\r\n<strong>}<\/strong><\/pre>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u4eca\u56de\u306fLaravel\u3067Twig\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u3092\u4f7f\u3046\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>Twig\u3092\u4f7f\u3063\u3066\u307f\u305f\u611f\u60f3\u3068\u3057\u3066\u306f\u3001\u57fa\u672c\u7684\u306bBlade\u3068\u540c\u3058\u3088\u3046\u306a\u69cb\u9020\u306b\u306a\u3063\u3066\u3044\u308b\u3082\u306e\u306e\u3001\u300c\u30d5\u30a3\u30eb\u30bf\u30fc\u6a5f\u80fd\u300d\u306f\u3068\u3066\u3082\u4fbf\u5229\u3060\u3068\u3044\u3046\u5370\u8c61\u3092\u53d7\u3051\u307e\u3057\u305f\u3002<\/p>\n<p>\u307e\u305f\u3001\u5909\u6570\u3092\u8868\u793a\u3059\u308b\u90e8\u5206\u306b\u306f<code>$<\/code>\u304c\u5fc5\u8981\u306a\u3044\u3068\u3044\u3046\u306e\u3082\u65b0\u611f\u899a\u3067\u3057\u305f\u3002\u3068\u3044\u3046\u306e\u3082\u3001<code>$<\/code>\u306f\u5de6\u624b\u3060\u3051\u3067Shift\u30ad\u30fc\u3092\u62bc\u3057\u306a\u304c\u3089<code>4<\/code>\u3092\u62bc\u3059\u3068\u3044\u3046\u3061\u3087\u3063\u3068\u3057\u305f\u624b\u9593\u3092\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u3067\u3001\u3053\u306e\u8a18\u8ff0\u6cd5\u306f\u6b63\u76f4\u7fa8\u307e\u3057\u304b\u3063\u305f\u308a\u3057\u307e\u3059\uff08\u7b11\uff09<\/p>\n<p>\u305f\u3060\u3057\u3001Laravel\u306fBlade\u3092\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30a8\u30f3\u30b8\u30f3\u3068\u3057\u3066\u958b\u767a\u3055\u308c\u305f\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306a\u306e\u3067\u3001\u3082\u3057\u304b\u3059\u308b\u3068\u3069\u3053\u304b\u3067Twig\u3068\u306e\u4e0d\u6574\u5408\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u3082\u3042\u308b\u306e\u3067\u3001\u305d\u308c\u306f\u30ea\u30b9\u30af\u8981\u56e0\u3068\u3057\u3066\u899a\u3048\u3066\u304a\u304f\u5fc5\u8981\u306f\u3042\u308a\u307e\u3059\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2595 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/7.png\" alt=\"\" width=\"226\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/7.png 226w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/7-212x300.png 212w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30a8\u30f3\u30b8\u30f3\u3068\u3044\u3048\u3070\u6709\u540d\u306aSmarty\u3084Laravel\u306b\u6a19\u6e96\u642d\u8f09\u3055\u308c\u3066\u3044\u308bBlade\u306a\u3069\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u3053\u3053\u6700\u8fd1PHP\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30a8\u30f3\u30b8\u30f3 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=2678\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u7c21\u5358\uff01Laravel\u3067twig\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u3092\u4f7f\u3046\u5b9f\u4f8b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":2688,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[123],"class_list":["post-2678","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-123"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2678"}],"version-history":[{"count":10,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2678\/revisions"}],"predecessor-version":[{"id":2742,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2678\/revisions\/2742"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/2688"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}