custom field
From Textpattern CMS User Documentation
<txp:custom_field />
The basic custom_field tag is a single tag and used to display the contents of a custom field.
Custom fields are useful when you need to output content having a consistent structure, usually in context to a particular type of article. Custom fields are defined in Advanced Preferences, and used in the Write panel. There are conditions to be aware of in each case, so be sure to read the following sections, respectively:
Also see the if_custom_field conditional tag, which provides more flexibility and power using custom fields.
Contents |
Attributes
Tag will accept the following attributes (case-sensitive):
- default="value"
- Default value to use when field is empty.
- escape="html"
- Escape HTML entities prior to echoing the field contents.
- Values:
htmlor unset - Default:
html - name="fieldname"
- Display specified custom field.
Examples
Example 1: Book Reviews
You might, for example, publish book reviews for which you add the author, the title of the book, the publishing company and the year of publication.
With:
- a custom field named "Book_Author" containing
J.R.R. Tolkien - a custom field named "Book_Title" containing
The Lord of the Rings - a custom field named "Book_Publisher" containing
HarperCollins - a custom field named "Book_Year" containing
2004
and an article form like the following:
<p><txp:custom_field name="Book_Author" />: <txp:custom_field name="Book_Title" /><br /> Published by <txp:custom_field name="Book_Publisher" /> in <txp:custom_field name="Book_Year" />.</p>
HTML returned would be:
<p>J.R.R. Tolkien: The Lord of the Rings<br /> Published by HarperCollins in 2004.</p>
Example 2: Power A Linklog
This works well with variation of Sencer's Txp bookmarklet.
With an article title of Textpattern, an excerpt of Textpattern is awesome., a custom field named "Link" containing http://textpattern.com/, and an article form like the following:
<div class="linklog-entry"> <div style="float: left;"><a href="<txp:custom_field name="Link" />"><txp:title /></a></div> <div style="float: right;"><txp:posted format="%d %d %Y" /></div><br> <txp:excerpt /> </div>
HTML returned would be:
<div class="linklog-entry"> <div style="float: left;"><a href="http://textpattern.com/">Textpattern</a></div> <div style="float: right;"><txp:posted format="08 Aug 2005" /></div> <p>Textpattern is awesome.</p> </div>
Other tags used: title, posted, excerpt
Example 3: Unescaping HTML output
With a custom field named "foo" containing:
<a href="../here/">
using the following:
<txp:custom_field name="foo" />
will return this hunk of HTML:
<a href="../here/">
whereas using:
<txp:custom_field name="foo" escape="" />
will render the URL as you'd expect, exactly as written in the custom field itself. Thus, it will be rendered as a link by the browser.




