From 61f82b0145f87d7397ea10c7c8a11ffadba25cb7 Mon Sep 17 00:00:00 2001 From: Hana Kim Date: Thu, 5 Mar 2026 21:38:22 -0500 Subject: static: display output container for runnable examples Examples on pkg.go.dev that are runnable but lack pre-defined output previously did not display the output container when they were executed. This was because the template only rendered the output
 block
conditionally if .Output was present.

Modified static/doc/example.tmpl to always render the output container
for runnable examples, hiding it by default if no initial output exists.
Updated the PlaygroundExampleController in static/shared/playground/playground.ts
to manage the visibility of this container when execution results are
received.

Added regression tests:
- A client-side unit test in static/shared/playground/playground.test.ts
- A server-side template test in internal/godoc/dochtml/dochtml_test.go

Fixes golang/go#75062

Change-Id: I37b3922c99d956ff1b139834e4625eb8d61b84cd
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/752184
kokoro-CI: kokoro 
Reviewed-by: Ethan Lee 
LUCI-TryBot-Result: Go LUCI 
---
 static/doc/example.tmpl | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

(limited to 'static/doc/example.tmpl')

diff --git a/static/doc/example.tmpl b/static/doc/example.tmpl
index ab54b246..ece580cf 100644
--- a/static/doc/example.tmpl
+++ b/static/doc/example.tmpl
@@ -15,7 +15,10 @@
       

Open in Go playground ยป

{{"\n" -}} {{- end -}} {{render_code .Example}}{{"\n" -}} - {{- if .Output -}}
Output:{{"\n\n"}}{{- .Output -}}
{{"\n" -}}{{- end -}} + {{- if or .Output .Play -}} +
Output:{{"\n"}}{{- .Output -}}
{{"\n" -}} + {{- end -}} {{"\n" -}} {{- if .Play -}}
-- cgit v1.3