Textpattern CMS uses tags as internal shorthand. This article is the fourth in a series of five concerning structural tags, which largely relate to the scaffolding of information management, and it covers the frequently-used `output_form` tag. The gist of `output_form` is that it will process a given form, and include it in the browser markup where appropriate.
Like many other Textpattern tags, `output_form` can be tweaked with the use of attributes. Unlike other tags, though, it only has a single attribute:
That’s it. In some respects, it’s a fiendishly useful tag that doesn’t need much in the way of extra functionality; the good stuff can go into the form construction, and the `output_form` tag can be called from a page to hook that good stuff into place. As well as being used on a page, `output_form` can be used in other forms. If you do go down the route of having forms importing other forms, be careful to avoid circular references and making things needlessly complex – after all, you or an associate may have to debug somewhere down the line if things go wrong.
Using `output_form` in its single tag format is simple – just point it to the form, and that’s it:
<txp:output_form name="information" />
Make sure the form being called is a miscellaneous form. Any other type of form might throw an error or give unpredictable results. A good example of `output_form` is to standardise a header or footer across the site. Multiple pages can refer to the same form via `output_form`, and making a change to said form will mean all the pages see the changes instantly.
Below is the bare bones example:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title><txp:site_name /></title> </head> <body> <txp:output_form name="navigation" /> <!-- page content here --> <txp:output_form name="footer" /> </body> </html>
Two forms are called: one for the site navigation, and one for the footer. These will be parsed and outputted to the browser for the viewer to see. Forms are not restricted to just visible content, however. A common use for `output_form` is to have the contents of the HTML `<head>` inside a form, giving the administrator an easy way to update header information when required. Like this:
<!DOCTYPE html> <html> <head> <txp:output_form name="html_head" /> </head> <body> […] </body> </html>
The two lines removed from the `<head>` can live in the `html_head` form, along with other directives.
Next time: `yield`.