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

PHPz
Release: 2024-02-11 09:00:10
forward
837 people have browsed it

"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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!