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 to template the contents of the <tbd>
element.
1<!DOCTYPE html>
2<html>
3 <head>
4 <meta charset='utf-8'>
5 <title ht-content='page.title,site.title'></title>
6 </head>
7 <body>
8 <!-- TODO -->
9 </body>
10</html>
The highlighted portion of this template will cause HyperTemplates to something something the <example>
element something.
Example output index.html
Let's see what happens when we process this template with the following template data.
1{}
The <example>
element will be removed because the example template data did not contain a page.title
property.
1<!DOCTYPE html>
2<html>
3 <head>
4 <meta charset='utf-8'>
5 <title ht-content='page.title,site.title'></title>
6 </head>
7 <body>
8 <!-- TODO -->
9 </body>
10</html>
Specification
Supported elements
The ht-not
attribute can be used with any HTML element.
1<!-- TODO -->
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".