Conditional
Use HTML conditional comments effortlessly
Install
Install the component from your command line
console
pnpm add jsx-emailpnpm add jsx-emailconsole
bun add jsx-emailbun add jsx-emailconsole
npm add jsx-emailnpm add jsx-emailconsole
yarn add jsx-emailyarn add jsx-emailUsage
Add the component to your email template. Include styles where needed.
jsx
import { Conditional, Head } from 'jsx-email';
const Email = () => {
return (
<Head>
<Conditional mso={true}>
<meta content="batman" />
</Conditional>
</Head>
);
};import { Conditional, Head } from 'jsx-email';
const Email = () => {
return (
<Head>
<Conditional mso={true}>
<meta content="batman" />
</Conditional>
</Head>
);
};Component Props
ts
interface ConditionalProps {
children?: React.ReactNode;
expression?: string;
mso?: boolean;
}interface ConditionalProps {
children?: React.ReactNode;
expression?: string;
mso?: boolean;
}INFO
The expression prop or the mso prop must be defined, but not both.
Props
ts
expression?: string;expression?: string;If provided, the string will be used as the conditional expression within the HTML comment. e.g. a value of lt ie 10 would result in a conditional comment block starting with <!--[if lt ie 10]>.
ts
head?: boolean;head?: boolean;If true, the conditional expression will be placed in the head section of your email template.
ts
mso?: boolean;mso?: boolean;If true, the conditional comment begins with <!--[if mso]>. If false, the conditional comment block uses a common hack and appears as <!--[if !mso]><!--> ... <!--<![endif]-->.