aboutsummaryrefslogtreecommitdiffhomepage
path: root/services/nuldoc/content/posts/2024-08-19
diff options
context:
space:
mode:
Diffstat (limited to 'services/nuldoc/content/posts/2024-08-19')
-rw-r--r--services/nuldoc/content/posts/2024-08-19/go-template-access-outer-scope-pipeline-within-with-or-range.md (renamed from services/nuldoc/content/posts/2024-08-19/go-template-access-outer-scope-pipeline-within-with-or-range.dj)15
1 files changed, 5 insertions, 10 deletions
diff --git a/services/nuldoc/content/posts/2024-08-19/go-template-access-outer-scope-pipeline-within-with-or-range.dj b/services/nuldoc/content/posts/2024-08-19/go-template-access-outer-scope-pipeline-within-with-or-range.md
index 6a6f9c3..c982145 100644
--- a/services/nuldoc/content/posts/2024-08-19/go-template-access-outer-scope-pipeline-within-with-or-range.dj
+++ b/services/nuldoc/content/posts/2024-08-19/go-template-access-outer-scope-pipeline-within-with-or-range.md
@@ -11,13 +11,11 @@ tags = [
date = "2024-08-19"
remark = "公開"
---
-{#tldr}
-# TL;DR
+# TL;DR {#tldr}
常にトップレベルを指す特殊変数 `$` を使えばよい。
-{#intro}
-# はじめに
+# はじめに {#intro}
Go には、標準ライブラリにテンプレートライブラリ `text/template` がある。
この `text/template` における制御構造、`with` と `range` は次のように使われる。
@@ -61,8 +59,7 @@ tmpl.Execute(out, Params{
})
```
-{#what-i-want-to-do}
-# やりたいこと
+# やりたいこと {#what-i-want-to-do}
今回おこないたいのは、`with` や `range` の中で、その外側で使われていたトップレベルのオブジェクトを参照することだ。
@@ -89,8 +86,7 @@ tmpl.Execute(out, Params{
しかしながら、頻発するシチュエーションにしてはあまりに不恰好である。よりスマートな方法が用意されているはずだ。
-{#solution}
-# 解決方法
+# 解決方法 {#solution}
常にトップレベルを指す特殊変数 `$` を使えばよい。
@@ -111,8 +107,7 @@ tmpl.Execute(out, Params{
> When execution begins, $ is set to the data argument passed to Execute, that is, to the starting value of dot.
-{#reference}
-# 参考
+# 参考 {#reference}
* [直接の出典である Stack Overflow の回答: "In a template how do you access an outer scope while inside of a "with" or "range" scope?"](https://stackoverflow.com/questions/14800204/in-a-template-how-do-you-access-an-outer-scope-while-inside-of-a-with-or-rang)
* [大元の出典である `text/template` の公式ドキュメント](https://pkg.go.dev/text/template#hdr-Variables)