Before/after 4.7 primer

23 May 2018

Keywords: shorten, optimize

Textpattern 4.7 introduces important new features (like themes, global attributes etc) that deserve each a separate discussion. But it also offers its users easier ways to achieve some common tasks that we briefly describe here.

Don’t pgonly anymore

We need to display previous/next page links before the articles list:

Before
<txp:article pgonly="1" />
<txp:newer /> - <txp:older />
<txp:article />
After
<txp:newer /> - <txp:older />
<txp:article />

Say not to lame <txp:else />

We need to hide some text under some condition, say in some section:

Before
<txp:if_section name="about">
<txp:else />
    Not about section.
</txp:if_section>
After
<txp:if_section not name="about">
    Not about section.
</txp:if_section>

Be valueless

Most of Boolean attributes 1 values can be skipped now:

Before
<txp:section link="1" title="1" />
After
<txp:section link title />

Enjoy wraptag new powers

We need to append a class pulled from some custom field:

Before
<txp:if_custom_field name="class"> class="<txp:custom_field name="class" />"</txp:if_custom_field>
After
<txp:custom_field name="class" wraptag=' class="<+>"' />

Welcome <txp:evaluate />

We need to display a breadcrumb only when corresponding articles exist:

Before
<txp:variable name="articles" value='<txp:article />' />
<txp:if_variable name="articles" value="">
<txp:else />
    <txp:breadcrumb />
    <txp:variable name="articles" />
</txp:if_variable>
After
<txp:evaluate test="article">
    <txp:breadcrumb />
    <txp:article />
</txp:evaluate>