Is it a bad practice to create a template language that is not valid HTML nor PHP (Stacy CMS)?
This is the template language of Stacy (a super light HTML/PHP CMS that doesn't use database开发者_如何学Go)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>@title, @name's Portfolio </title>
<link rel="alternate" type="application/atom+xml" href="@root_path/?/feed/">
<link rel="stylesheet" href="@root_path/public/docs/css/screen.css" type="text/css" media="screen">
</head>
<body>
<div id="container">
<h1 class="col three">
<a href="@root_path">@name</a>
<strong>@profession</strong>
</h1>
<em class="col three">@email</em>
<hr>
:navigation
<div id="content" class="col eight">
<p class="date col one">@date</p>
<div class="description col six">
<h2 class="col six"><a href="@root_path">@title</a></h2>
@content
</div>
<hr>
<p id="project-count" class="col one"><em>№</em> @index/@siblings_count</p>
<p id="gallery-count" class="col one">
<em>№</em> <span>1/1</span>
</p>
<div id="gallery-navigation" class="col three">
<p><a href="#" id="next-image">Next image</a> <em>→</em></p>
<p><a href="#" id="previous-image">Previous image</a> <em>←</em></p>
</div>
<div class="col four">
if $siblings do
:next-page
:previous-page
endif
</div>
:media
</div>
I wonder if those @
and :
would produce some sort of problems? Is it a bad practice since is not valid HTML nor PHP?
Is it a bad practice since is not valid HTML nor PHP?
As long as the end result the template engine generates is valid HTML, there is no fundamental problem with this. The template itself will never be shown to the end user, just the result.
However, this kind of syntax will break a HTML IDE's highlighting, or may cause problems when editing the template file with a WYSIWYG editor. If you do a lot of that (or have a non-programming person edit the templates), you may be better off looking for an engine that has a HTML compatible template format (although I can't think of one off the top of my head.)
This is definitely the way most template engines operate.
If it displays as valid HTML to the end user, it should be fine.
This looks like a template file, those : and @ will be replaced with content from the CMS.
This actually isn't invalid markup, it's just not doing what you'd expect.
Arguably having a templating system that doesn't look like HTML or PHP is a good thing – you are less likely to accidentally forget to parse it, or accidentally parse it twice.
the point is is that those '@''s are variables that get replaced with valid content on the server side by your application before your web server ever serves it. That means when a browser queries the web server it gets back the page with the appropriate content plugged in where the '@''s were and it never sees the '@''s
if you want to see that in action just compare the page template in your app's source with the page source code in your browser
精彩评论