Doctype in Templates

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Doctype in Templates

Post by cmb » Sun Apr 13, 2014 10:44 pm

Hello Community,

we already had issues regarding restrictions on which HTML features to use in the past, and I expect more to come in the future. That is because HTML5 brings more and more features, and we want to generate standards compliant markup, but the core has no easy information, let alone control, about resp. over the generated doctype.

A possible solution would be to read template.htm and to parse the doctype. However, that seems to be hard to accomplish, if at all possible. And anyway, in my opinion the doctype doesn't belong in the template, because it affects plugins as well. (Instead of hard-coding (a) certain doctype(s) a template designer might tag his templates regarding the supported markup language/version.)

So we should consider a simple and efficient solution, namely to introduce a new template tag, say

Code: Select all

<?php echo doctype();?>
The core would emit the appropriate doctype (plus the html start tag) depending on a configuration option. xhtml_endtags would not be sufficient (consider HTML 4.01 vs. HTML5), so a new option, say markup_language (?), seems sensible. This should be an enum (empty, doctypes for HTML 4.01 trans., XHMTL 1.0 trans and HTML5) (which would be displayed as a selectbox in the admin area). If this option is not empty, we would use it internally instead of xhtml_endtags.

To make use of that new template tag existing templates would have to be adapted, but even if that would not happen, the result is most likely a non-validating but nonetheless fully working site (and at least less broken than if we would emit the doctype automatically, i.e. without the template calling a template tag).

An even simpler solution would be to rely on the HTML5 doctype, and to advice template designers to use this in the future, and to tell users to update their templates accordingly. Basically that's what CMSimple v4 does, so we would stay compatible in this regard. OTOH template designers could use the following to stay compatible with CMSimple_XH and CMSimple v4:

Code: Select all

<?php if (!function_exists('doctype')) {function doctype() {return '<!DOCTYPE html>';}}?>
<?php echo doctype();?>
Christoph
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

Re: Doctype in Templates

Post by svasti » Fri Apr 18, 2014 6:05 pm

cmb wrote:An even simpler solution would be to rely on the HTML5 doctype, and to advice template designers to use this in the future
+1
This seems to be the way to go. And it makes life simpler.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Doctype in Templates

Post by cmb » Fri Apr 25, 2014 6:37 pm

svasti wrote:
cmb wrote:An even simpler solution would be to rely on the HTML5 doctype, and to advice template designers to use this in the future
+1
This seems to be the way to go. And it makes life simpler.
Does that give us a free ticket to use HTML5 markup in coming releases?

For instance, I've received a feature request regarding the semantic markup of the lastupdate of pages (page_params). HTML5 defines the time element, which would be very reasonable to use[1]. However, it would be invalid HTML 4.01/XHTML 1.0 and worse, in older browsers (IE <= 8) such unknown elements can't be styled (at least without tricks) and might give problems regarding JavaScript.

We should consider introducing a respective configuration option.

PS: A sample replacement for the respective code in plugins/page_params/index.php (requires PHP 5 because of the 'c' format):

Code: Select all

    if ($pd_current['show_last_edit'] > 0
        && $pd_current['last_edit'] !== ''
    ) {
        $temp = '<time class="entry-date updated" datetime="'
            . date('c', $pd_current['last_edit'])
            . '" pubdate = "pubdate">'
            . $plugin_tx['page_params']['last_edit'] .  ' '
            . date($tx['lastupdate']['dateformat'], $pd_current['last_edit'])
            . '</time>';
        if ($pd_current['show_last_edit'] == 1) {
            $c[$pd_s] .= $temp;
        } else {
            $c[$pd_s] = $temp . $c[$pd_s];
        }
    }
Last edited by cmb on Fri Apr 25, 2014 7:39 pm, edited 1 time in total.
Reason: added PS
Christoph M. Becker – Plugins for CMSimple_XH

Termin
Posts: 101
Joined: Thu Jan 27, 2011 8:55 am
Contact:

Re: Doctype in Templates

Post by Termin » Sat Apr 26, 2014 10:39 am

For strictly browser (IE <= 8) will be enough for one line:

Code: Select all

<script>document.createElement('time');</script>
more: http://www.pixelcom.crimea.ua/sovmestimost-html5.html

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Doctype in Templates

Post by cmb » Sat Apr 26, 2014 8:39 pm

Termin wrote:For strictly browser (IE <= 8) will be enough for one line:
ACK. However, there is still a (theoretical?) problem, if JavaScript is disabled.
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

Re: Doctype in Templates

Post by svasti » Sat Jun 21, 2014 3:49 pm

Now thinking a bit more about it before voting:
cmb wrote:So we should consider a simple and efficient solution, namely to introduce a new template tag, say

Code: Select all

<?php echo doctype();?>
I think the idea is very good but it comes a few years too late. What would be exactly the disadvantage of always sticking with <!DOCTYPE html>?

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Doctype in Templates

Post by cmb » Sat Jun 21, 2014 4:16 pm

svasti wrote:What would be exactly the disadvantage of always sticking with <!DOCTYPE html>?
Most likely none, unless the W3C or WHATWG or whoever might sometimes decide to introduce another doctype declaration.

Probably I was thinking too conservatively, and too generally (actually the doctype declaration shouldn't be part of the template, but it's no problem, if this declaration is always the same).

BTW: one minor problem with HTML5: TinyMCE 3 uses the name attribute when inserting an anchor on a page.
Christoph M. Becker – Plugins for CMSimple_XH

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Doctype in Templates

Post by cmb » Fri Jun 27, 2014 11:45 am

I just learned that the W3C HTML5 specification has recently advanced from a "Candidate Recommendation" to a "Last Call Working Draft", and
The Last Call period is expected to finish on 15 July 2014.
IMHO that is sufficient to recommend the HTML5 Doctype for templates (especially as at least basic HTML5 is widely implemented). We will have to update the XH wiki accordingly (and consequently the templates shipped with XH)--any volunteers?
Christoph M. Becker – Plugins for CMSimple_XH

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Doctype in Templates

Post by cmb » Fri Sep 05, 2014 10:50 pm

cmb wrote:I just learned that the W3C HTML5 specification has recently advanced from a "Candidate Recommendation" to a "Last Call Working Draft"
Nonsense. :oops: Of course, making a "Candidate Recommendation" to a "Last Call Working Draft" is not advancement, but rather a step back. Anyhow, W3C is back to "Candidate Recommendtion" now.
cmb wrote:We will have to update the XH wiki accordingly (and consequently the templates shipped with XH)--any volunteers?
As I was the only voter on this item, and I voted for "only recommend HTML5 Doctype", changing the shipped templates is not appropriate. Furthermore strictly recommending the HTML5 is questionable[1], so I have added this as tip to the respective articles (http://www.cmsimple-xh.org/wiki/doku.ph ... eclaration and http://www.cmsimple-xh.org/wiki/doku.ph ... l#template) in the Wiki. (BTW: both articles need a review, IMO, and the German translation is defintely out-dated. We need volunteers...)

[1] While the HTML5 doctype works in "all" browsers, HTML5 is not standardized (i.e. a W3C recommendation) yet. And actually I have some doubts whether this will ever happen, considering the WHATWG suggesting a "living standard".
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Doctype in Templates

Post by Tata » Sat Sep 06, 2014 5:28 am

If it would't require inadequately much work, then a solution

Code: Select all

<?php if (!function_exists('old_function')) {function doctype() {return 'new_function';}}?>
<?php echo new_function();?>
as an internal plugin used for some reasonable time seems to me to be good and safe fallback.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

Post Reply