Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-03-09 20:02:51

floodfish
Member
From: Brooklyn, NY
Registered: 2007-01-11
Posts: 155
Website

best way to put comments in code?

Any suggestions/strategies for how to best add comments to txp code? Putting <txp:hide> around everything takes up an awful lot of time and space, and is hard to scan for visually, versus just prefacing lines with a # or // or wrapping with /* … */ or all sorts of other niceties we’re used to elsewhere.

Offline

#2 2010-03-09 20:06:23

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: best way to put comments in code?

This has been covered before – see this comment for a good explanation.

Offline

#3 2010-03-09 20:12:04

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: best way to put comments in code?

Only way in TXP is <txp:hide>. TXP’s syntax isn’t programming language.

<txp:hide>
	I'm not returned. They return empty when they see me :-(
</txp:hide>

If you want to use comment lines used in programming languages, you need to evaluate the block of code. For example:

<txp:php>
	# Yeah. I'm a comment and ppl like me green.
</txp:php>

Or if you have allowed raw PHP from TXP’s settings:

<?
	# Yeah. I'm a comment and ppl like me green.
?>

Which is bit shorter.

Or you can use HTML comments which are renderet to the public page:

<!--
	Yeah. I'm a comment and ppl like me green.
-->

If TXP did use comment lines used in programming languages, we, users, would need to escape lines that aren’t comments but use comment syntax.

Offline

#4 2010-03-09 20:16:58

floodfish
Member
From: Brooklyn, NY
Registered: 2007-01-11
Posts: 155
Website

Re: best way to put comments in code?

Thanks, Jukka.

I just wish there was a way to add comments (that won’t render to the public) that didn’t take up so much space. I was hoping someone knew of a trick I hadn’t thought of!

Offline

#5 2010-03-11 11:02:39

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: best way to put comments in code?

I’m using <!-- html comments -->. They are very good for simple debugging and are fast to write :) If you want to hide them from source code at production mode you can use plugins, which strip unused comments – aks_header for example.


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#6 2010-03-11 17:59:35

floodfish
Member
From: Brooklyn, NY
Registered: 2007-01-11
Posts: 155
Website

Re: best way to put comments in code?

Aha! Thanks Victor. That sounds perfect for my needs, actually. And I could do with some of the other functions of aks_header, too, I think.

Offline

#7 2010-03-11 23:30:34

floodfish
Member
From: Brooklyn, NY
Registered: 2007-01-11
Posts: 155
Website

Re: best way to put comments in code?

OK, so I actually see no default or obvious way to strip html comments via aks_header. How are you doing that?

Offline

#8 2010-03-12 07:36:19

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: best way to put comments in code?

Ouch, my bad, aks_header can’t strip html comments. then you can try me plugin and place it after aks_header, if you want aks_header’s features.

# Name: thg_trim v0.2 (compressed)
# Type: Client side plugin
# Strips whitespace and HTML comments.
# Author: Victor the_ghost Rusakovich
# URL: http://victorus.net/
# Recommended load order: 5

# .....................................................................
# This is a plugin for Textpattern - http://textpattern.com/
# To install: textpattern > admin > plugins
# Paste the following text into the 'Install plugin' box:
# .....................................................................

H4sIAAAAAAAAA82TQW/aMBTHz42U7+BaqNAKMIUAqcnYdYf1sk27NCtKHRNHI3Zkv9BVpd+9
tkmqqSv3HaLkvff//Z/tPGf0ekKfDY0ollnF8crQmGIQxQZ0WblwQXHWgFDaBdMlxT9LBkoj
EHxTCGUAfWtM9lvtSyacxPq1wKbRpYdsRgDUlJC9ZxszlhyIq1m/PdemVNJFM4on46l3uaY4
54bpsoauaFfy3a6qNuhRlMBNnTGOMpmjLz9uvyKmqopLMGOntdthKvfbmUfWlRCkeaX23CAB
1e5N7PG/3LZaVShDxraRRRhsG8lce9QdyKCXAZgh6oGwgssweA6Ds55qAH1CdaYNH7SVVRjY
CiFtjWtelBvN653tMsCpPKT6kMIhOR+N7u7Xv65GozUeImwfRxzxzteyb2ifOGQwPqTm8uqz
pUh/iPr9D7D3LeGU/3uhTqV7nLx9d8h/CJw84dNIGGgOjZY+YeOXMGhHBp5qPzJ29iZtSvBd
7S/FDcWJ/RPrxM3V+mIHK/hT024uLgrndNalH1T+RI45lyL/ShPifRLiPP2YUqx0znXbf95e
hyo/fk0pns3Z4mHBbibxdsmWsziPFvOIRXHO2IzF0xyvXl4BbgjO3s4DAAA=

Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#9 2010-03-12 15:10:07

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: best way to put comments in code?

Just keep in mind that when removing comments (from the code everytime the page is requested), slows the delivery and requires more resources from the server. Altho, TXP’s tag parsing and function calls have same impact.

Offline

#10 2010-03-12 23:00:57

woof
Member
Registered: 2004-08-01
Posts: 128

Re: best way to put comments in code?

I use TypeIt4Me to replace the strings <!-- & --> with <txp:hide> and </txp:hide> automatically as I type. It is handy for inserting any frequently used text like txp tags and saves a lot of time.

(Tip: make sure “dont append trigger” is checked in in prefs>settings >expansion)

Offline

Board footer

Powered by FluxBB