Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2005-11-24 20:51:49
- KurtRaschke
- Plugin Author
- Registered: 2004-05-16
- Posts: 275
Embedding Textpattern
I know, you’re not supposed to want to embed Textpattern, but sometimes it’s the most elegant way to solve a problem. The present solution, though, is not terribly elegant, as including <code>publish.php</code> can potentially create problems with output buffering and HTTP headers.
However, the core idea is sound—being able to parse Textpattern tags in non-Textpattern PHP pages. So, I’ve produced a variant of <code>publish.php</code>, what I’m calling embed.php, which makes it a bit easier and safer to embed Textpattern (no trouble with HTTP headers or the like).
It’s essentially a drop-in replacement for publish.php, which you can use in one of two ways:
<ul>
<li>Run your whole script’s output through the TXP parser:
<code>include ‘/path/to/textpattern/config.php’;
include $txpcfg[‘txpath’].’/embed.php’;
ob_start(‘parse’);</code></li>
<li>Run a given string through the TXP parser:
<code>include ‘/path/to/textpattern/config.php’;
include $txpcfg[‘txpath’].’/embed.php’;
$tags = “<txp:sitename />”;
$output = parse($tags);</code></li>
</ul>
All the usual warnings apply—this can and probably will break in strange ways. But for simple things, like getting the content of an article to display on a page outside of Textpattern, or a list of links, it should work. Would I use it to show whole paginated article lists? No. That’s what <code>publish.php</code> is there for.
In the past I’ve recommended including publish.php, which as I’ve noted is potentially error-prone, so this may make things a little easier for those who need to embed Textpattern.
-Kurt
kurt@kurtraschke.com
Offline
Pages: 1