Home >php教程 >PHP开发 >Several misunderstandings about beetl

Several misunderstandings about beetl

高洛峰
高洛峰Original
2016-11-22 15:19:071850browse

Beetl is becoming more and more popular in China. The community website has thousands of daily visits, and the number of downloads remains at around 20 per day (Maven cannot be counted). Before the QQ group was full, it had kicked out waves of inactive members and a small number of people whose values ​​​​do not conform to it (this article was written when the Ali mooncake incident was fermenting). As his fame grew, so did his negative comments. I have listed some misunderstandings in negative comments

Beetl lacks documentation

If you search for beetl tutorials and documents, you will find that you can basically only locate beetl official website documents and a small number of beetl usage instructions written by the author. It cannot be considered that there are only a few beetl users. caused. This just shows that the beetl official website documents are well written, and the community provides various demos and timely answers to questions. Compared with JSP, Freemaker has countless articles on how to use a loop, and countless authors work tirelessly to write articles explaining these simple concepts. Beetl does not have such an article or even a video. Beetl's syntax is based on JS, and it was originally developed by Chinese people. There is no difficulty in documentation and communication

Beetl uses a4558806285d5b7820bdaa0b90aa4d26, which is like jsp and is very ugly.

This is also a misunderstanding. In fact, beetl delimiters can allow any symbols, such as PHP-like b26da186e11666e6dd99f28d6205715c, HTML-like comments bf33294179d3c78988260bd09aed7d25, or simple @ and reply Pair the car line feed symbols, as shown below.

@ for(u in userList){
<span>${uLP.index}:
${u.name}</span>@}

Beetl’s syntax is like Java

Beetl syntax refers to javascript, so it does look like Java in form, which is why Beetl’s learning curve is low. But Beetl, as a template language, is specially used for output, which is much better than Java-based JSP. For example, in the above code, uLP is a built-in loop variable. You can get the current index, odd and even rows and other information. You only need to add it after the loop variable. Just add LP, which is specially used for template output. In addition, beetl supports elsefor. As the above code does not enter the loop body, you can use elsefor for explanation

@for(){

@}elsefor{
<span> 无记录 </span>
@}

Beetl template language has the following features customized for templates:

Omitted ternary expression

Safe output

select- case syntax

html tag

formatted output

directly call java methods or attributes

various layout functions

template variables

strict MVC control

These syntaxes are template-specific syntaxes, completely the same as java Two things

I prefer imperative rather than scripted template languages.

Some people prefer imperative template syntax like Velocity because it has fewer instructions. But the shortcomings are also obvious. When dealing with complex logic rendering, it is often more ugly and difficult to write. beetl is a script-based template engine. It may have a lot of syntax, but based on JS, it is not difficult to understand. The script-based syntax is also easier to deal with complex rendering logic. Don't be fooled by the helloworld example of the imperative template engine. It looks cool, but when used in a project, it ends up being the same as scripting.

Template performance is not important

I have also seen on the Internet that instead of optimizing the template engine, it is better to optimize database access. I think it is right. If I would first consider optimizing database access and other places , but if these are optimized, you can also use a better template engine to improve line performance. Beetl performance is 6 times that of freemaker and 2 times that of JSP (there are also three-party tests that are 3 times that of JSP. It may be that JSP is used too much. Caused by JSTL), the template engine involves CPU calculations and IO output, which is actually a relatively resource-consuming part of web applications. I think that if this consumption can be reduced, it will be effective in improving system performance. If your database access has been optimized well and the business code has been written perfectly, why not use a template engine with better performance? Beetl does not need to do any additional operations to achieve the ultimate performance. It is already very good. performance.

The back-end template engine is not important anymore

This is a fact. Now the front-end template engine is becoming more and more important. Beetl has also developed a beetljs, but because of its huge size, it is really expensive compared to those 7K and 8K template engines. I didn’t take action, so I never launched it. We can only optimize the size later, reduce the grammatical features, and then choose the right time to launch it.

Even if the trend is like this, I think the back-end template engine still has its advantages, and it is still very important at present:

The back-end template engine function, maintainability, etc. are far stronger than the front-end template engine

The back-end template engine is located in The back-end, so it is easy to obtain back-end data, while the front-end template engine needs to prepare all data

The back-end template engine has a wide range of applications: there are also code generation, static page generation, and some back-end template functions, such as sending emails, text messages, etc.

In most companies, there is a lack of front-end talent. Using front-end template engines will cause more people to focus on the front-end. Companies should try to use less front-end simulation board engines before they are ready for this change

In terms of development efficiency, back-end template engines have been popular for many years, so they should be more efficient than front-end template engines

Back-end template engines are suitable for SEO optimization , the front-end template engine is difficult

The back-end template engine has a layout function

I think the correct way to use the template engine currently is to use the front-end + back-end together. Of course, the front-end template engine is also learning from the back-end simulation engine function, which will It is becoming more and more perfect, and maybe one day it will really dominate web applications. Moreover, architecture-oriented services, the widespread use of mobile terminals, and front-end simulation engines are indeed becoming more and more important


Statement:
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