Home  >  Article  >  Backend Development  >  Template parsing error: template::1: unexpected '=" in operand

Template parsing error: template::1: unexpected '=" in operand

PHPz
PHPzforward
2024-02-11 09:00:10853browse

"Template

php editor Baicao introduces you to the problem of template parsing errors. During the template parsing process, we often encounter some errors, the most common of which is the "Template parsing error: Template::1: Unexpected "=" in operand" error. This error usually occurs when we use the equal sign "=" to assign a value. To avoid this error, we need to double-check the code and make sure the equal sign is used correctly. Through correct template parsing, we can avoid this error and improve the readability and maintainability of the code.

Question content

template parsing error: template: :1: unexpected "=" in operand

The above error occurred when executing the following command in windows,

docker inspect --format="{{range $key, $value := .Config.Env}}{{if eq (index (split $value "=") 0) "VERSION"}}{{$value}}{{end}}{{end}}" octopusbi-agent-backend

What could be the problem?

Solution

"=" symbol problem, if double quotes are used within a string enclosed by double quotes (") marks (") tag, you must add a backslash (\ ) before each double quote (") tag, excluding the first and last A double quote (") mark.

Example:-

"hello "your_name""  <-- wrong
"hello \"your_name\""  <-- correct

windows

As I mentioned before, I changed "=" to \"=\" and after that, I came across another version with the name " Issues related to other string values ​​of ". To do this I also had to change "version" to \"version\" and it worked as I expected.

So the final command is,

docker inspect --format="{{range $key, $value := .config.env}}{{if eq (index (split $value \"=\") 0) \"version\"}}{{$value}}{{end}}{{end}}" octopusbi-agent-backend

ubuntu

I ran the same command in ubuntu with the opening and closing quotes marked with single quotes (') and left the remaining double quotes (") marked.

So the final command is,

docker inspect --format='{{range $key, $value := .Config.Env}}{{if eq (index (split $value "=") 0) "VERSION"}}{{$value}}{{end}}{{end}}' octopusbi-agent-backend

Summary

If you use the dockerspect command with the --format option,

  • In windows:-
    1. The format string must begin with a double quote (") mark.
    2. If you want to use double quotation marks (") in the format string, use \".
  • In ubuntu:-
    1. The format string must begin with a single quote (') mark.
    2. Feel free to use double quotation marks (") in the format string.

The shortest is that if quotes are required, we must use double quotes (") markers within the format string in both environments.

The above is the detailed content of Template parsing error: template::1: unexpected '=" in operand. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete