Textpattern CMS Template Tags

<txp:site_url /> single tag, 0 attributes

site_url

The site_url tag is a single tag which returns the full URL of the site (as defined in the Basic Preferences) as text.

If you maintain local development versions of your live sites and import databases between them, then this tag is extremely valuable for ensuring your domain links are never confused (thus broken) between the two locations (see example 1).

<txp:site_url /> 3 examples

Maintain accurate domain paths

The idea is that you don’t break URL paths after importing a database from local development to live, or visa versa. By using this tag it will automatically be relative to a given site and you’ll never have to manually edit broken domain paths again. A classic example is with navigation links.

<ul id="navmenu">
<li class="articles"><a class="nopad" href="<txp:site_url />articles" title="Articles">Articles</a></li>
<li class="photos"><a href="<txp:site_url />photos" title="Photographs">Photographs</a></li>
</ul>

HTML header paths

In your Head section of your HTML pages you might have a variety of links to locations relative to the local server, such as CSS files, Javascript files, a favicon and so forth. The relevance is similar to example #1, you want to ensure the paths are accurate relative to the server if a database has been imported from another location. Following is an example for the shortcut icon file (if you use one).

<link rel="shortcut icon" href="<txp:site_url />favicon.ico" />

Display a hyperlink to download a text file

<a href="<txp:site_url />download.txt">Download</a>