From a65bb9609284d273f0aa232dbaf69597c87f5a12 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 15 Jun 2025 13:12:46 +0900 Subject: feat(blog/nuldoc): merge consecutive text nodes --- .../index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'vhosts/blog/public/posts/2024-08-19/go-template-access-outer-scope-pipeline-within-with-or-range/index.html') diff --git a/vhosts/blog/public/posts/2024-08-19/go-template-access-outer-scope-pipeline-within-with-or-range/index.html b/vhosts/blog/public/posts/2024-08-19/go-template-access-outer-scope-pipeline-within-with-or-range/index.html index 418b5203..18730a09 100644 --- a/vhosts/blog/public/posts/2024-08-19/go-template-access-outer-scope-pipeline-within-with-or-range/index.html +++ b/vhosts/blog/public/posts/2024-08-19/go-template-access-outer-scope-pipeline-within-with-or-range/index.html @@ -66,7 +66,7 @@

はじめに

- Go には、標準ライブラリにテンプレートライブラリ text/template がある。 この text/template における制御構造、withrange は次のように使われる。 + Go には、標準ライブラリにテンプレートライブラリ text/template がある。この text/template における制御構造、withrange は次のように使われる。

# {{ .Title }}
@@ -87,7 +87,7 @@
               text/template. は、現在の操作対象を表す特殊なオブジェクトである。
             

- withrange は、. を変更する効果を持つ。 with は引数に渡されたオブジェクトを . へセットして、内部のテンプレートを実行する。 range は引数に渡されたイテレート可能なオブジェクトに対し、それぞれの要素を . へセットして、要素の個数だけ内部のテンプレートを実行する。 + withrange は、. を変更する効果を持つ。with は引数に渡されたオブジェクトを . へセットして、内部のテンプレートを実行する。range は引数に渡されたイテレート可能なオブジェクトに対し、それぞれの要素を . へセットして、要素の個数だけ内部のテンプレートを実行する。

つまりこのテンプレートは、次のような構造をレンダリングしている (Execute() の第2引数)。 @@ -122,7 +122,7 @@ {{ end }}

- withrange は、. を自身の対象オブジェクトに変更するので、 単に {{ with .User }} の中で .Title と書いても、それは UserTitle プロパティを参照しているとみなされる。 + withrange は、. を自身の対象オブジェクトに変更するので、単に {{ with .User }} の中で .Title と書いても、それは UserTitle プロパティを参照しているとみなされる。

text/template では変数が使えるので、テンプレートの先頭で @@ -152,7 +152,7 @@ {{ end }}

- $ は、テンプレートが実行されるときに渡されたオブジェクトを指す。 これを使えば現在の . に関係なくトップレベルを参照できる。 + $ は、テンプレートが実行されるときに渡されたオブジェクトを指す。これを使えば現在の . に関係なくトップレベルを参照できる。

このことは、text/template の公式ドキュメントにも以下のように記載されている。 -- cgit v1.2.3-70-g09d2