Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2007-08-27 01:37:43
- Logoleptic
- Plugin Author
- From: Kansas, USA
- Registered: 2004-02-29
- Posts: 482
Question: tag parsing order
This starts out with a specific question about a plugin of my own, and then branches out into more general questions about how templates are parsed by Textpattern…
When I was testing my aam_typogrify plugin, I checked to make sure that it worked together with Mary’s upm_textile. I found that it did, so long as the upm_textile tag was placed inside any tags from my plugin:
<txp:aam_typogrify><txp:upm_textile>
<txp:excerpt />
</txp:upm_textile></txp:aam_typogrify>
At the time I interpreted this as Textpattern evaluating plugins and/or template tags from the inside out, and I explained it as such in the documentation. More recently, however, I’ve read that plugins are evaluated in the order they were installed.
The regular expressions used by parts of Typogrify (for widow-suppression and initial quotes, specifically) only allow it to operate on a limited set of (X)HTML elements. If upm_textile were installed after aam_typogrify, then Typogrify wouldn’t find any of those (X)HTML tags in the un-Textiled text and fail to either suppress widows or wrap initial quotes in classed spans… right? If I’m on the right track here, it would explain some inconsistencies I’ve seen in the plugin’s behavior. It would also shed some light on the one bug report I’ve received.
This leads me to some broader questions about Textpattern templates:
- In a situation like mine, where compatibility between two plugins is desired, is there a way to ensure this compatibility without using
include_plugin()
? Since upm_textile isn’t required for my plugin to work, I’d like to avoid displaying an error message when it’s absent. - Are built-in template tags evaluated before plugin tags, after them, or in the order they occur within the template? The tag trace would seem to point to the last possibility as correct.
- By default, are non-conditional container tags parsed before or after the the tags they contain?
- In what order are page and form templates parsed by Textpattern? For example, would the output of
<txp:article form="foo" />
be available to any tags that wrap around it? - What causes a particular part of a template to get parsed during the second pass? Is there a way to force this to happen for a plugin?
Thanks in advance for your help. I’m still new at writing plugins and getting under the hood of Textpattern, and I appreciate the guidance.
Offline
#2 2007-08-27 03:12:16
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Question: tag parsing order
You can check to see if upm_textile (or any tag for that matter) is installed and activated very easily:
if (function_exists('upm_textile'))
{
// upm_textile is installed and activated
}
It’s probably a good idea to make use of a variable that you can re-use, if you will need to test that more than once:
$upm_textile_installed = function_exists('upm_textile');
Tags are parsed outside in, actually. This is because of how the regular expression works.
Here it is, in English:
From the beginning, look for anything that looks like a Textpattern tag. See if the tag actually exists by looking for a function named the same. If it exists, pass everything contained by the tag (
$thing
) to that plugin.
There’s no other precedence taken, they’re parsed in the order they appear in the page. Textpattern will do this a second time after all the results of the first pass are complete, to make sure nothing was missed the first time ‘round. There is no way to force another pass, it is just a hard-coded second-run of the same parsing function on what was returned by the first pass.
So for the code you posted, it looks like:
aam_typography looks like a tag and a function with that name exists, so let’s pass the following (
$thing
) to that function:
<txp:upm_textile>
<txp:excerpt />
</txp:upm_textile>
Now your plugin runs the parser again:
upm_textile looks like a tag and a function with that name exists, so let’s pass the following (
$thing
) to that function:
<txp:excerpt />
My plugin parses this content once more:
excerpt looks like a tag and a function with that name exists, so let’s simply return the contents of that function (because it is not a container, there is nothing to pass to it).
My plugin runs Textile on it, then returns it to your function, which runs it’s own magic on the final contents before returning it to the page.
What are the inconsistencies you’ve seen?
Offline
Pages: 1