Go to main content

Custom field

Contents

Syntax

<txp:custom_field />

The 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 the Preferences panel, and used in the Write panel. There are conditions to be aware of in each case, so be sure to read the Defining custom fields information.

Also see the if_custom_field conditional tag, which provides more flexibility and power using custom fields.

Attributes

Tag will accept the following attributes (case-sensitive) as well as the global attributes :

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:

  1. a custom field named Book_Author containing J.R.R. Tolkien,
  2. a custom field named Book_Title containing The Lord of the Rings,
  3. a custom field named Book_Publisher containing HarperCollins,
  4. a custom field named Book_Year containing 2004.

and an ‘article’ type 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

With an article title of Textpattern, an excerpt of Textpattern is awesome!, a custom field named Link_url containing https://textpattern.com/, and an ‘article’ type form like the following:

<article class="linklog-entry">
    <h1>
        <a href="<txp:custom_field name="Link_url" />"><txp:title /></a>
    </h1>
    <p>
        <time datetime="<txp:posted format="iso8601" />" itemprop="datePublished">
            <txp:posted format="%d %d %Y" />
        </time>
    </p>
    <txp:excerpt />
</article>

HTML returned would be:

<article class="linklog-entry">
    <h1>
        <a href="https://textpattern.com/">Textpattern</a>
    </h1>
    <p>
        <time datetime="2005-08-14T15:08:12Z" itemprop="datePublished">14 Aug 2005</time>
    </p>
    <p>Textpattern is awesome!</p>
</article>

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:

&#60;a href=&#34;../here/&#34;&#62;

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.

If you notice any kind of problem with this page's construction or content (outdated information, typos, broken links, or whatever), open an issue to have it sorted. Or have a go at it yourself. :)