Cannot use strings functions in user defined go template for serve http

What is the problem you are having with rclone?

Cannot use strings functions inside my modified go template. I'm not use if this is possible.

For example this is what I'm trying to do:

{{ if (.Name | strings.Contains ".jpg") }}
     // my HTML code
    // my HTML code

Here is the default go template on github for reference : go template

(Note: I'm running the DEV version as I tried to manually import or define the "strings" in some files located in this folder, but after compiling and installing I still get the same error.)

Run the command 'rclone version' and share the full output of the command.

rclone v1.62.0-DEV

  • os/version: ubuntu 22.04 (64 bit)
  • os/kernel: 5.15.0-60-generic (aarch64)
  • os/type: linux
  • os/arch: arm64 (ARMv8 compatible)
  • go/version: go1.18.1
  • go/linking: dynamic
  • go/tags: none

Which cloud storage system are you using? (eg Google Drive)

Google Drive

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone serve http --addr :8080 -vv --vfs-cache-mode=off --template /my_template.html --user xxx --pass xxx gdrive:

The rclone config contents with secrets removed.

Does not apply

A log from the command with the -vv flag

failed to init server: failed to get template: template: index:307: function "strings" not defined

You can only use the functions that rclone has included in the template and this does not include the strings functions :frowning:

See this Go Template compare if string ends in or contains another string - Stack Overflow for more explanation.

Yeah, that's what I was thinking. I added the strings functions and now I can use them in my html template. Would it be a good idea to include them in the master branch in the near future? I'm not sure if others will benefit from this or maybe it was just me. Thanks!

Send a pull request - this sounds useful - thank you :slight_smile:

sure, thank you!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.