Textpattern: Context in depth Page 3 of 8

Parsing global context

Terms introduced on this page:

Context elements
Individual aspects of the total context.
Implied context
Aspects of global context that are inferred rather than given explicitly.
Article context
Context for a particular article.
Section context
Always required in global context.
Determines the page template.
Defaults to the “default” section.
Image context
Context for a particular image.
Category context
Context for a particular category.
Image-category context
Context for a particular image category

Context elements

To , Txp global context (or page context) comes from the URL, while local context (or tag context) is controlled by the site architect through the use of context-setting tags. Now we’ll look at the components that go into context, which I will call context elements.

Txp offers several URL schemes (i.e., Permanent Link Modes). The basic function of all these schemes is to convert URLs to global contexts. URLs must be unambiguous, i.e., there must be only one global context for a given URL.

The reverse need not be true: on most Txp sites there are two URLs for any given global context. That’s because most sites aren’t set to “messy” mode, but messy URLs work no matter the site’s Permanent Link Mode preference. (Take note of this page’s URL. Then try this:
http://ipsedixit.net/?id=131
which brings you back to this page, i.e., it gives the same global context.)

Implied context

Messy mode isn’t a popular URL scheme, partly because it isn’t very user-friendly. Note the example above: ?id=131 tells almost nothing to a user, even a user familiar with URL query strings. But it’s enough to give Txp the full global context. This isn’t because ?id=131 is some kind of secret code (it means just what it seems — this page has the ID 131), it’s because some aspects of global context are inferred. I’ll call such elements the implied context.

To Txp, ID means article ID. So ?id=131 means that article #131 is part of this page’s context. We can say this page has article context. It also has section context. Every Txp page must have section context; among other things, this determines which template is used. The messy URL doesn’t state the section, so Txp infers the section context from the article ID — every Txp article is assigned to a section. (In this case it is the “txp“ section, as you can also see by looking at this page’s normal URL.)

Global context for
http://ipsedixit.net/txp/131/parsing-global-context
URL path Permlink Mode Section Article
txp/131/context-elements /section/id/title txp 131

Minimum global context

Now compare these URLs:

As in the earlier example, both URLs point to the same page, or global context. Again, the messy URL makes the context clear: the “s” in the query string stands for “section”. No other context can be inferred from this information alone, so with these URLs the global context is simply the “txp“ section.

Section is the only required element of global context, so this example represents the minimum global context.

Global context for http://ipsedixit.net/txp/
URL path Permlink Mode Section
txp/ /section/id/title txp

Category context

Txp version 4.3.0 introduced new context-related behavior, as my Textpattern Gallery Demo shows. The context at these two URLs, the canonical version and its messy equivalent, gives an example:

context=image is misleading. The example page does not have image context, i.e., the context of a particular image. It has category context (from the c in the query string), the context of a particular category (“sleep”, in this case). context=image refers to the category type, which would have been a better name for this parameter. (Indeed, type is the attribute name that sets this in category_list.) We could say the page has image-category context.

Default section context

Every Txp site has a special section called the “default section”. You can think of it as a sort of super-section, encompassing all other site sections.

What about section context? Lacking either an implied section (as in the first example), or an explicitly stated one (as in the second), section context defaults to the “default” section. Hence the example page’s global context is the “sleep” image category and the “default” section.

Global context for http://gallery.ipsedixit.net/category/image/sleep/
URL path Permlink Mode Section Category Type
category/image/sleep/ /title default sleep image

Posted 2011-01-08 (last modified 2011-04-10)