ht-not
attribute reference
Overview
The ht-not
attribute removes the target HTML element if the defined conditional expression evaluates to true
.
If the conditional expression evaluates to false
, the target HTML element is retained.
Example
This example shows the ht-not
attribute being used for conditional templating of a blockquote citation.
1<blockquote>
2 <span ht-content='html:content'></span>
3 <cite ht-if='cite'>
4 <span ht-not='href' ht-content='text:cite'></span>
5 <a ht-if='href' ht-attrs='href:href' ht-content='text:cite'></a>
6 </cite>
7</blockquote>
In this example the ht-not
attribute is used together with the ht-if
attribute on the following line.
If the href
property is empty, the ht-not
condition will evaluate to false so the <span>
element will be retained; but the ht-if
condition will also evaluate to false so the <a>
element will be removed.
Specification
Supported elements
The ht-not
attribute can be used with any HTML element.
Attribute syntax
The ht-not
attribute uses the ht-if
attribute syntax, with the opposite effect (see exclusive templating).
When an ht-not
attribute evaluates true
, the target HTML element is removed.
Example
1<address ht-not='page.author.kind,site.author.kind==person' ht-content='page.author.address'></address>
In this example, HyperTemplates will remove the <address>
element if the value of the page.author.kind
or site.author.kind
template data property matches the expected conditional value of person
.
Exclusive templating
The ht-not
attribute is used for exclusive templating.
If the condition evaluates as true
, the target HTML element is removed.
See ht-if
for inclusive templating.
Conditional values
The ht-not
attribute can optionally define a comma-separated list of one or more expected conditional values (see attribute syntax).
To explain how conditional values are evaluated, consider the following example template data.
1{
2 page: {
3 title: "Introducing: HyperTemplates",
4 author: {
5 name: "Herd Works Inc.",
6 href: "https://herd.works",
7 kind: "organization",
8 },
9 }
10}
Given this example template data, the conditional expression ht-not='page.author.kind'
would evaluate true
because the template data property exists and is not empty.
However, the conditional expression ht-if='page.author.kind==person'
would evaluate true
because the page.author.kind
property has a value of "organization", not "person".