Understanding and Using Textpattern CMS Tags: Global Tags

I’ve introduced you to the tag concept in Textpattern CMS; this is a great time to go into a little more detail and show you some examples of how tags integrate into the everyday workings of your Textpattern-maintained website. When I refer to Textpattern tags, this is the term used to describe the internal commands that Textpattern interprets into performing actions. The tag concept is a pretty neat and powerful idea, and is worth looking into if you want to customise your Arvixe + Textpattern site. In this post I’ll be explaining some of the global tags that can be used in Textpattern. I’m deliberately staring with some of the more straightforward tags so you can best understand the processes involved. As always, comments and feedback are welcomed in the comments.

I’ll start by picking three easy-to-understand tags:

  • <txp:site_name />
  • <txp:site_slogan />
  • <txp:site_url />

I’ve started with these tags because they are don’t have any attributes (options) with them. In each case, you can use the tags in an article, in a form, or in a page and the output will be the same wherever the tag is used. The <txp:site_name /> tag is a shortcut to output the name of the site as defined in the preferences area of the administration interface. You want to change the name of your site somewhere down the line? No problem! Just use the <txp:site_name /> tag in your code and all instances will be replaced by the current name of the site. You may, for example, want to have an <h3> header on your page with your current site name. Like this:

<h3><txp:site_name /></h3>

If your site name is set to The Example Shipping Company, Inc, then this is what would be rendered in the markup:

<h3>The Example Shipping Company, Inc</h3>

In a similar vein, you can use <txp:site_slogan /> to output the tagline of your site, again taken from the preferences area of the administration backend. An example of how you might use these two tags together to bulk up your header, like this:

<h3><txp:site_name /></h3>
<h4><txp:site_slogan /></h4>

The slogan might be set to Delivering Promises Since 1949, and the new markup would be:

<h3>The Example Shipping Company, Inc</h3>
<h4>Delivering Promises Since 1949</h4>

Now, the third of the trio is <txp:site_url />. You have less control over this than the other two, and it’s simply the URL of the website you’re running. You can find the URL of the site in the preferences panel of the administration area alongside the <txp:site_name /> and <txp:site_slogan /> settings. Let’s assume the URL of the site is set to http://example.com, and in order to tell people your website address you could use the tag in its simplest form:

<txp:site_url />

This will output a raw URL which, frankly, might not be much use on its own. The fun starts when you hook the URL into another tag. In this example, we can make the <txp:site_name /> <h3> text a hyperlink to the homepage of the site. Like this:

<h3><a href="<txp:site_url />"><txp:site_name /></a></h3>
<h4><txp:site_slogan /></h4>

…which, when processed into markup, will look like this:

<h3><a href="http://example.com/">The Example Shipping Company, Inc</a></h3>
<h4>Delivering Promises Since 1949</h4>

The mix of (X)HTML and Textpattern tags is perfectly acceptable and expected. We can take the above example a stage further and have the slogan link to another page on the site which details the history of the company. In this case, the page we want to link to is http://example.com/history

<h3><a href="<txp:site_url />"><txp:site_name /></a></h3>
<h4><a href="<txp:site_url />history"><txp:site_slogan /></h4>

Note the addition of the <txp:site_url /> tag on the second line, immediately followed by history. There is no slash required as the <txp:site_url /> tag inserts that for you. When the <txp:site_url /> tag is processed, the history part is tacked on the end of the URL and, you guessed it, it looks like this in markup:

<h3><a href="http://example.com/">The Example Shipping Company, Inc</a></h3>
<h4><a href="http://example.com/history">Delivering Promises Since 1949</a></h4>

There are more global tags in Textpattern, this how-to was a primer in how to get started. You can find the full list of tags at the Textpattern tag reference page. I hope you’ll join me next time as I introduce you to article tags and throw in some attributes for good measure. It’ll be fun, you should come back and see.

Looking for quality Textpattern Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , | Posted under Textpattern | RSS 2.0

Author Spotlight

Pete Cooper

Pete Cooper has been using Textpattern since 2005. Textpattern is his preferred CMS weapon of choice. Its logical and flexible approach to content management makes Pete happy, as does its lightweight core and helpful user community. Pete's website - petecooper.org - runs on top of Textpattern and chronicles his day-to-day experiences from his home near the Atlantic in north Cornwall, United Kingdom.

Leave a Reply

Your email address will not be published. Required fields are marked *

3 + = 8

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>