There is Python Server Pages which uses <% ... %> to delimit Python code, but is otherwise very similar to PHP. Using this gives you all of the Python language & standard lib so it satisfies most of the requirements.
However, it should be noted that the PHP nature of mixing logic and templates is (mostly) an antipattern.
A language where whitespace is syntactically significant, used in HTML tags?
<% if condition: %><% action1 %><% action2 %>
How do I know whether action2 is also part of the if block or not; and how do I write the other version?
However, it should be noted that the PHP nature of mixing logic and templates is (mostly) an antipattern.
Yes, but beginners want it, because it has the smallest overhead for trivial projects. Later, when they learn more, they can separate the logic and templates. Here is a code that leads to antipatterns, but is nice to have—if you fix it, it will look much more difficult.
I’ve never used psp, but the documentation page seems to indicate what happens with indentation. It looks like it would be parsed as:
<p>
if condition:
....<b>
action1
</b>
action2
</p>
I have no idea how to get either “proper” behaviour, and I’m not in a position to experiment, but I’m sure it’s possible (that would be a fairly large omission).
Yes, but beginners want it, because it has the smallest overhead for trivial projects. Later, when they learn more, they can separate the logic and templates.
Yes, I agree that it is good for beginners; I was merely mentioning that point.
Designing a HTML page can be complicated, especially if client requires complicated things, animations and other effects, pixel precision, and compatibility with older browsers. Also the page may contain non-trivial JavaScript code. Mix it up with PHP code (or Java code), and you get something very complicated. If you do some change in design, it may break the code. If you do some change in code, it may break the design. In a larger team you can have one person who is HTML expert but not a programmer (or a very bad programmer), and a coder who is not a HTML expert. If you make them both edit the same page, it is unpleasant for both of them.
Unfortunately, things like this are done very often. I often see it in Java web development. In theory, you have all the tools you need, so you don’t have to put any Java code in the JSP files. (There are special tags for “if then else” and “for each”, which is all you need in most templates.) But most people do it anyway, just because they can and it’s the fastest way to write it, but then it is horrible to maintain.
You get clean design by separating different aspects of the work. If one file is reading from the database, second file processes the data, and third file formats the data in nice HTML, that’s good. If lines 1-46, 67-78, 89-123, 150-176, 189-235 format the data in HTML, the lines 46-65, 124-128 read from database, and the lines 66, 79-88, 129-149 process the data, that’s bad, because it’s difficult to read. And if something is difficult to read, many problems follow automatically; it’s difficult to find bugs, it’s difficult to make changes.
Even if I write a simple PHP file, I always put code in the first part and design in the second part, clearly separated. With a larger project, it must be two different files.
There are few reasons, e.g. thesequestions. But as an incomplete summary, it means your templates are language independent and it enforces a style of coding and application design that is easier to test and maintain.
(This isn’t to say that logicful templates are never appropriate: for quick hacks and prototyping they are perfect!)
There is Python Server Pages which uses
<% ... %>
to delimit Python code, but is otherwise very similar to PHP. Using this gives you all of the Python language & standard lib so it satisfies most of the requirements.However, it should be noted that the PHP nature of mixing logic and templates is (mostly) an antipattern.
A language where whitespace is syntactically significant, used in HTML tags?
How do I know whether action2 is also part of the if block or not; and how do I write the other version?
Yes, but beginners want it, because it has the smallest overhead for trivial projects. Later, when they learn more, they can separate the logic and templates. Here is a code that leads to antipatterns, but is nice to have—if you fix it, it will look much more difficult.
I’ve never used psp, but the documentation page seems to indicate what happens with indentation. It looks like it would be parsed as:
I have no idea how to get either “proper” behaviour, and I’m not in a position to experiment, but I’m sure it’s possible (that would be a fairly large omission).
Yes, I agree that it is good for beginners; I was merely mentioning that point.
Why is it an antipattern?
Designing a HTML page can be complicated, especially if client requires complicated things, animations and other effects, pixel precision, and compatibility with older browsers. Also the page may contain non-trivial JavaScript code. Mix it up with PHP code (or Java code), and you get something very complicated. If you do some change in design, it may break the code. If you do some change in code, it may break the design. In a larger team you can have one person who is HTML expert but not a programmer (or a very bad programmer), and a coder who is not a HTML expert. If you make them both edit the same page, it is unpleasant for both of them.
Unfortunately, things like this are done very often. I often see it in Java web development. In theory, you have all the tools you need, so you don’t have to put any Java code in the JSP files. (There are special tags for “if then else” and “for each”, which is all you need in most templates.) But most people do it anyway, just because they can and it’s the fastest way to write it, but then it is horrible to maintain.
You get clean design by separating different aspects of the work. If one file is reading from the database, second file processes the data, and third file formats the data in nice HTML, that’s good. If lines 1-46, 67-78, 89-123, 150-176, 189-235 format the data in HTML, the lines 46-65, 124-128 read from database, and the lines 66, 79-88, 129-149 process the data, that’s bad, because it’s difficult to read. And if something is difficult to read, many problems follow automatically; it’s difficult to find bugs, it’s difficult to make changes.
Even if I write a simple PHP file, I always put code in the first part and design in the second part, clearly separated. With a larger project, it must be two different files.
There are few reasons, e.g. these questions. But as an incomplete summary, it means your templates are language independent and it enforces a style of coding and application design that is easier to test and maintain.
(This isn’t to say that logicful templates are never appropriate: for quick hacks and prototyping they are perfect!)