Home > Article > Backend Development > Template parsing error: template::1: unexpected '=" in operand
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.
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?
"="
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
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
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
If you use the dockerspect
command with the --format
option,
"
) mark."
) in the format string, use \"
. '
) mark. "
) 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!