Conditional Host Name Plugin for Textpattern: aam_if_host
This is a plugin for Textpattern users who stage website development across multiple domains or subdomains. With aam_if_host, your templates can do one thing on the in-development site, and another on the “live” site.
NOTE: requires version 4.0.4 or higher of the open-source Textpattern content management system.
Download aam_if_host-0.10.txt (3.2KB, 83 downloads)
If you have any trouble with this plugin, let me know in the plugin’s support thread on the Textpattern forum. You can also leave a comment on this blog post.
Usage
Let’s say, for example, that you’re using some complex JavaScript on your site. On the public site you want to serve a script that’s compressed with Dean Edwards’s Packer, but while you’re developing the site you’d like to keep the scripts readable for debugging. Here’s how:
<txp:aam_if_host name="localhost,dev.example.com">
<script type="text/javascript" src="<txp:site_url />js/myscript.js"></script>
<txp:else />
<script type="text/javascript" src="<txp:site_url />js/myscript.packed.js"></script>
</txp:aam_if_host>
The name attribute takes a comma-separated list of server names, which the current host will be compared with by the plugin. If your Textpattern site is on one of those hosts, then the contents of the tag will be parsed. The default value for name is “localhost”.
As with the built-in conditional tags, you can use <txp:else /> to specify what happens if the condition is false (e.g. the site is on www.example.com instead of localhost or dev.example.com).
License
Copyright © 2007 Adam Messinger.
Distributed under the terms of the BSD license.






