Skip to content

Commit 61c5f4e

Browse files
Merge pull request #2485 from redis/DOC-6013-c-bug-tces
DOC-6013 bug fix for C examples being available on C#-only pages
2 parents 24a0c5e + 014c9c7 commit 61c5f4e

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

build/tcedocs/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,22 @@ The following example shows the `connect` step of a Python example:
259259
```
260260
{{< clients-example set="set_and_get" step="connect" lang_filter="Python" />}}
261261
```
262+
262263
The programming language name should match the value in the Hugo configuration file.
264+
265+
#### Language Filter Syntax and Matching
266+
267+
The `lang_filter` parameter accepts a **comma-separated list of exact language names**:
268+
269+
```
270+
{{< clients-example set="example_id" lang_filter="C#-Sync,C#-Async" />}}
271+
```
272+
273+
**Important**: Language names must match exactly as they appear in `config.toml`. The matching is **exact**, not substring-based:
274+
275+
-`lang_filter="C#-Sync,C#-Async"` - Shows only C# sync and async tabs
276+
-`lang_filter="C"` - Does NOT match "C#-Sync" or "C#-Async" (exact match only)
277+
-`lang_filter="Python,Node.js"` - Shows Python and Node.js tabs
278+
-`lang_filter="Python,Node"` - Does NOT match "Node.js" (must use exact name)
279+
280+
**Common pitfall**: If you use a language name that is a substring of another language name (e.g., "C" is a substring of "C#-Sync"), the filter will NOT accidentally match the longer name. Each language in the filter list must match exactly.

build/tcedocs/SPECIFICATION.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,6 +2140,26 @@ OK
21402140
{{< /clients-example >}}
21412141
```
21422142

2143+
### Language Filter Matching Behavior
2144+
2145+
The `lang_filter` parameter uses **exact matching** on comma-separated language names:
2146+
2147+
**Matching Logic**:
2148+
1. Split the filter string by commas (e.g., `"C#-Sync,C#-Async"``["C#-Sync", "C#-Async"]`)
2149+
2. Trim whitespace from each language name
2150+
3. For each configured language in `config.toml`, check if it exactly matches any value in the filter list
2151+
4. Only include languages that match exactly
2152+
2153+
**Examples**:
2154+
- `lang_filter="C#-Sync,C#-Async"` → Shows only C# sync and async tabs
2155+
- `lang_filter="Python"` → Shows only Python tab
2156+
- `lang_filter="Python,Node.js"` → Shows Python and Node.js tabs
2157+
- `lang_filter="C"` → Shows only C tab (does NOT match "C#-Sync" or "C#-Async")
2158+
2159+
**Important**: Language names must match exactly as they appear in `config.toml`. This prevents accidental matches when one language name is a substring of another (e.g., "C" is a substring of "C#-Sync", but they are treated as distinct languages).
2160+
2161+
**Implementation**: See `layouts/partials/tabbed-clients-example.html` for the matching logic.
2162+
21432163

21442164
## Lessons Learned: Adding the C (hiredis) Client
21452165

layouts/partials/tabbed-clients-example.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,19 @@
3434
{{ $language := index $example "language" }}
3535
{{ $quickstartSlug := index $clientConfig "quickstartSlug" }}
3636

37-
{{ if and ($example) (or (eq $lang "") (strings.Contains $lang $client)) }}
37+
{{/* Check if language filter matches: either no filter or exact match in comma-separated list */}}
38+
{{ $langMatches := false }}
39+
{{ if eq $lang "" }}
40+
{{ $langMatches = true }}
41+
{{ else }}
42+
{{ range $filterLang := split $lang "," }}
43+
{{ if eq (strings.TrimSpace $filterLang) $client }}
44+
{{ $langMatches = true }}
45+
{{ end }}
46+
{{ end }}
47+
{{ end }}
48+
49+
{{ if and ($example) $langMatches }}
3850
{{ $examplePath := index $example "target" }}
3951
{{ $options := printf "linenos=false" }}
4052

0 commit comments

Comments
 (0)