0

This is the template language of Stacy (a super light HTML/PHP CMS that doesn't use database)

<!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>&#8470;</em> @index/@siblings_count</p>
        <p id="gallery-count" class="col one">
          <em>&#8470;</em> <span>1/1</span>
        </p>
        <div id="gallery-navigation" class="col three">
          <p><a href="#" id="next-image">Next image</a> <em>&rarr;</em></p>
          <p><a href="#" id="previous-image">Previous image</a> <em>&larr;</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?

alexchenco
  • 53,565
  • 76
  • 241
  • 413
  • I assume that the various instances of `@index` (and other `@`-prefaced variables) are simply place-holders for values coming from elsewhere. It looks like the template could *output* valid (x)html from this template. Reference: http://staceyapp.com/documentation/variable-types/variables/ – David Thomas Apr 10 '11 at 15:19
  • @David Thomas Yes, it is. SO it doesn't matter as long as the output is valid HTML? – alexchenco Apr 10 '11 at 15:19
  • The template doesn't matter, because that's only the framework into which information's slotted, and then output to the browser. There are arguments that invalid html pages also have their place, and aren't necessarily a problem, depending on their purpose/use-case. See: http://stackoverflow.com/questions/994856/so-what-if-custom-html-attributes-arent-valid-xhtml, and http://stackoverflow.com/questions/1337928/whats-the-point-of-valid-css-html (among many, many others...). – David Thomas Apr 10 '11 at 15:22
  • validates for me using w3c validator (after closing the .container div and html tags) `@` and `:` are valid content for html – knittl Apr 10 '11 at 15:24

4 Answers4

5

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.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
2

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.

John Godspeed
  • 1,387
  • 2
  • 10
  • 16
1

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.

Rich Bradshaw
  • 71,795
  • 44
  • 182
  • 241
0

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

Craig
  • 419
  • 4
  • 19