PDA

View Full Version : vB template commenting options



monForum
Mon 5th Jun '06, 5:43am
In a recent post in the vB 3.6 discussion area (http://www.vbulletin.com/forum/showpost.php?p=1139224&postcount=476), I made the following point regarding the possibility of 3.6 including the option for vB specific commenting in templates, which would not be passed through to the final HTML of the pages delivered. I realise now that that thread is primarily chit-chat over release notes, so am hoping I can make the same comments here and see if this might be a possibility. I think it would be a great step forward, not just for usability, but also bandwidth performance.


As a styles and template coder, I have found that the comments make it much easier for non-coders to follow what is going on in their code, and the indentation allows easy marrying up of tags to ensure that everything opened has subsequently been closed. Most vB owners will not get involved to heavily with the php files, but will modify their templates at some point, either throuogh experimentation or following instructions. The easier that the HTML is to read, the better it is for those who modify it, especially those who are not confident or fluent in HTML.

I'd be very keen for some release (perhaps 3.6) to allow for some kind of vB commenting in templates: rather than use HTML commenting tags, which remain in the page as it's parsed out to the user's browser, perhaps allow vB templates to be coded with special template codes (perhaps lines begining '##' or something akin to that), which allows scripters to make extremely verbose comments in templates, which are parsed out / ignored by vB when processing the template and delivering the page.

For example, if a snippet of a template is currently marked as follows:


<!-- This is the bit to insert the image variable: -->
<br>
<img src="$variable1">
<!-- And here is the description: -->
etc.

In the current system, that's exactly what the HTML of the end page will look like, save for the variables being expanded. But if a system of vB commenting were used, the above fictional template snipped could be coded as:


## This is the bit to insert the image variable:
<br>
<img src="$variable1">
## And here is the description:
etc.

vB would ignore its comment lines on parsing, so the actual HTML delivered on the page would be:


<br>
<img src="$variable1">
etc.

A system like this would allow coders / template designers to be exceptionally thorough in commenting up their changes, without those comments being passed to the actual pages. In the end this could save actually quite a lot of delivery bandwidth, especially on larger sites; and it's also just nice to be able to add comments into template that one might not want the curious end-user, who views the source, to see.

An added benefit is that the HTML comment tags could still be used, for those instances in which it might actually be helpful or desireable for the comment to appear in the final pages.

I know some other forum systems use internal commenting like this for templates and skins -- it would be a real asset to the streamlining of vB, I think, if this could be incorporated. It might not be such a far-off idea for 3.6, actually, given that it should be relatively easy to code in: just a line in the global template parser that instructs vB to ignore any line beginning ## (or whatever the comment code might be).

Any possibility of this?

slappy
Thu 15th Jun '06, 5:06pm
I found several ways to do this through a google search:

First, you could use a TMPL_IF construct that is always false:

<TMPL_IF NAME="comment">
This is a comment as long as the code never defines the variable "comment"
</TMPL_IF>

or you could write a simple filter that strips out all your comments when you
load the template:

my $filter = sub {
my $text_ref = shift;
$$text_ref =~ s/\<\<\!\-\-.*?\-\-\>\>//g;
};

my $template = HTML::Template->new(filename => $template_file,
filter => $filter);


The second one is probably preferrable, but you could use something besides <<! >>
as the delimiters, Since they are not valid HTML, and also they are not easily
distinguishable from regular comments.

Another said there is no need to escape all those html chars. The following works for him --

# create new template
my $template = HTML::Template->new(
filename => $template,
global_vars => 1,
loop_context_vars => 1,
filter => sub { $$ =~
s/<!--#.*?-->//g; }
);


You could also use HTML::Clean to do this. Also strips the comments from JavaScript, empty lines, etc before it prints. (configurable).

http://search.cpan.org/~lindner/HTML-Clean-0.8/lib/HTML/Clean.pm

Regards,

Colin F
Thu 15th Jun '06, 5:35pm
He wants to add comments to templates, and not to the PHP code.

slappy
Thu 15th Jun '06, 6:12pm
Yep! I realized that after my initial post and removed the part about php file commenting. Hope the second attempt for comment html is on the mark.

There's also a plug-in available on vB.org titled; "Remove all (Template-)Comments from any HTML-Output" which one would assume discusses something about "how to comment and have it non-printing."

http://www.vbulletin.org/forum/showthread.php?t=117790

Developer comments: "vBulletin 3.6 will have an option to setup the order of execution for plugins within the same hook - meanwhile for vBulletin 3.5.x you have to use vbPluginOrder if there are more plugins within the hook my HTMLmodifier uses"

http://www.vbulletin.org/forum/showthread.php?t=111679

Regards,