Skip to content

tpl/strings: Add strings.ReplacePairs function#14598

Merged
bep merged 1 commit intogohugoio:masterfrom
jmooring:feat/strings-replace-pairs-14954
Mar 7, 2026
Merged

tpl/strings: Add strings.ReplacePairs function#14598
bep merged 1 commit intogohugoio:masterfrom
jmooring:feat/strings-replace-pairs-14954

Conversation

@jmooring
Copy link
Member

@jmooring jmooring commented Mar 6, 2026

Closes #14594

I recognize that the type checking (types.TypeToString) is more strict than in other strings functions, but for this particular function using something like cast.ToStringSliceE just doesn't feel right. So we're strict (string or any of the template types) on both the input and the replacement pairs.

The signature is:

strings.ReplacePairs OLD NEW [OLD NEW ...] INPUT

So you can do this:

{{ "aabbcc" | strings.ReplacePairs "a" "x" "b" "y" "c" "z" }} → xxyyzz

Or this:

{{ $pairs := slice
  "a" "x"
  "b" "y"
  "c" "z"
}}
{{ "aabbcc" | strings.ReplacePairs $pairs }} → xxyyzz

docs: https://deploy-preview-3424--gohugoio.netlify.app/functions/strings/replacepairs/

@gemini-code-assist
Copy link

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

@jmooring jmooring force-pushed the feat/strings-replace-pairs-14954 branch from 2cb68a1 to dd1a5af Compare March 7, 2026 16:50
@jmooring jmooring marked this pull request as draft March 7, 2026 16:52
@jmooring jmooring force-pushed the feat/strings-replace-pairs-14954 branch 2 times, most recently from 5df8e9f to c182f73 Compare March 7, 2026 16:58
@jmooring jmooring marked this pull request as ready for review March 7, 2026 16:58
@gemini-code-assist
Copy link

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

@jmooring jmooring force-pushed the feat/strings-replace-pairs-14954 branch from c182f73 to 94c0c94 Compare March 7, 2026 17:50
@bep bep merged commit 13a95b9 into gohugoio:master Mar 7, 2026
6 checks passed
@jmooring jmooring deleted the feat/strings-replace-pairs-14954 branch March 7, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add strings.ReplacePairs

2 participants