Skip to content

Minor Error in Templating substr Documentation #2517

@dpthorngren

Description

@dpthorngren

Description

There is a minor error in the description of the templating basic string functions. I've copied the example from the documentation into the issue example field. The issue is in the final line, which does not run:
- echo "{{substr .TEXT 0 5}}" # "Hello"
The error given is:
template: :1:15: executing "" at <.TEXT>: wrong type for value; expected int; got string

Consulting the slim-spring documentation, the string argument should be last. Either of the following would work:
- echo "{{.TEXT | substr 0 5}}" # "Hello"
- echo "{{substr 0 5 .TEXT}}" # "Hello"

Sorry to bother you with a minor issue, but it confused me for a bit. I appreciate the work put into this project. I can do a PR if it helps, though honestly it's maybe too trivial to bother with that.

Version

3.45.4+35b03f9

Operating system

N/A

Experiments Enabled

No response

Example Taskfile

version: 3

tasks:
  string-basic:
    vars:
      MESSAGE: '  Hello World  '
      NAME: 'john doe'
      TEXT: "Hello World"
    cmds:
      - echo "{{.MESSAGE | trim}}"          # "Hello World"
      - echo "{{.NAME | title}}"            # "John Doe"
      - echo "{{.NAME | upper}}"            # "JOHN DOE"
      - echo "{{.MESSAGE | lower}}"         # "hello world"
      - echo "{{.NAME | trunc 4}}"          # "john"
      - echo "{{"test" | repeat 3}}"        # "testtesttest"
      - echo "{{substr .TEXT 0 5}}"      # "Hello

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: docsChanges related to documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions