Textpattern tips, tutorials and code snippets

Hide or comment out content

Here is a very simple tip for hiding text, tags or other content while actively working on a site.

While working on new sites or design iterations one needs from time to time to remove content, leave a comment or suppress a tag or output. The normal method is simply to remove the content, but this can end up with working against you if you can’t remember later what you deleted, or you don’t have a backup (can’t tell you how many times I made this mistake in the past!).

The txp:hide tag

This little used Textpattern tag can help you a lot in many situations:

  1. When working with a team on a site and you need to leave comments in the code
  2. When you need to hide or suppress a portion of text or code in the page template
  3. When you want to test different code without removing the original code

An example

The txp:hide tag instructs TXP to hide whatever is wrapped inside the tag itself, like so:

Try another side menu, this one does not set an active class...
<ol class="work-list">
<txp:article_custom section="work" limit="20" class="active">
<li><txp:permlink><txp:title /></txp:permlink></li>

Lets try this one instead!

<ol class="work-list">
<txp:article_custom section="work" limit="20" class="active">
<li <txp:if_article_id> class="active"</txp:if_article_id>><txp:permlink><txp:title /></txp:permlink></li>

Although a simple tip, it can be very productive in your workflow.

4 Comments Comment feed

What are the key benefits over HTML <!-- comment -->

  • HTML comments cannot be nested;
  • ?

@Vladas – For normal comments the HTML equivalent is fine, but for TXP tags one needs to use txp:hide. Its just a method that works for all comments, tags and notes.

There is another benefit: a html-commented piece of source code remains leggible even on the client’s browser (in the source code). <txp:hide> holds this comment in the template only. So you can use it for template-specific comments which will not be sent to the client.

Thanks for this tip.

  • Dan
  • 24 November 2009

Awesome, thanks. Just what I was looking for; couldn’t found it in the docs.

Add a comment

Use Textile help to style your comments