Free, open-source variable modifiers for ExpressionEngine 7.3+. They work on any template variable: custom fields, embed parameters, {segment_N}, and early-parsed variables from other add-ons such as Mo' Variables' {get:...}. Like EE's own modifiers, they chain: {title:strip_tags:title_case}.
There are two kinds:
- Guards output a value only when it passes a check, and otherwise a fallback. They reject rather than reshape:
54247' UNION SELECT 1--is not a whole number, so:integergives the fallback, not542471. Use them on values from the request or from editors before they reach SQL, URLs, attributes or tag parameters. - Formatters change how text reads, such as its case. They leave HTML tags, entities and
{variables}alone.
Contributions are welcome: see CONTRIBUTING.md, or open an issue.
- Copy the
extra_modifiersfolder intosystem/user/addons/. - That's it. ExpressionEngine registers add-on modifiers for every add-on folder it finds, so there is no install step and nothing to configure.
Each modifier is also available with the add-on's prefix, such as :extra_modifiers_integer. If another add-on registers a modifier with the same name, the bare name may run that add-on's version; the prefixed name always runs this one.
| Guards | Formatters |
|---|---|
:integer whole numbers |
:strip_tags remove HTML |
:integer_list lists of IDs |
:word_limit shorten to N words |
:decimal decimal numbers |
:word_count words or reading time |
:one_of a value from a list |
:substr part of the text |
:one_of_list several values from a list |
:highlight mark search words |
:slug URL slugs |
:nl2br line breaks to <br> |
:date real dates |
:external_links target/rel on outside links |
:email email addresses |
:encode_email hide addresses from scrapers |
:safe_url http/https links |
:lowercase |
:uuid UUIDs |
:uppercase |
:hex_color hex colours |
:ucfirst |
:ip IP addresses |
:title_case |
:charset allowed characters |
:sentence_case |
:base64 base64 values |
:pad pad to a length |
:yes_no yes/no words |
:roman Roman numerals |
:is_true truthy values (also :is_false) |
:hash sha256, md5 … |
:not_empty visible content (also :has_content) |
:random pick from a list |
:fallback a value for empty values |
:base64_encode also :base64_decode |
- Spaces at either end of a parameter are trimmed by EE, so
output_separator=", "arrives as",". Write spaces as where they matter:output_separator=", "gives,. (output_separatordecodes entities for this reason.) - In a chain, every modifier receives every parameter.
{x:strip_tags:random count="2"}passescountto:strip_tagstoo, which ignores it. Where two modifiers in a chain use the same parameter name, add the modifier's name to aim it at one:random:separator=",".
Every guard decodes HTML entities and trims surrounding whitespace before checking, because some add-ons hand values over already encoded (a quote as '). Judging the decoded value means an encoded quote is rejected, not stripped into extra digits.
Every guard accepts these parameters:
| Parameter | Default | Effect |
|---|---|---|
default |
empty | Output when the value fails |
min_length |
none | Fewer characters than this fails |
max_length |
none | More characters than this fails |
Because the fallback is empty unless set, guards work in conditionals: {if "{get:id:integer}"}…{/if}. (For tags inside the conditional, see Using guards safely.)
Before using guards in SQL or tag parameters, read Using guards safely: a variable that doesn't exist never reaches the modifier, and some EE parameters ignore an empty value.
Outputs the value only when the whole of it is a whole number.
{get:id:integer} 54247, or nothing
{embed:entry_id:integer default="0"} 54247, or 0
{segment_3:integer unsigned="yes"} no negative numbers
{get:page:integer min="1" max="500" default="1"} 1 to 500, else 1
| Parameter | Default | Effect |
|---|---|---|
unsigned |
no | yes rejects negative numbers |
min, max |
none | Inclusive range. A min or max that isn't itself a whole number is ignored |
- The output is normalised: a leading
+and leading zeros are dropped (007gives7). - Only the digits 0–9 count; other scripts' digits, decimals,
1e5and0x1Agive the fallback. - Without
min,maxormax_lengththere is no size limit: a 30-digit number passes. Addmax_length="10"or a range if that matters.
ExpressionEngine escapes values passed to its own tags' parameters, but {exp:query sql="..."} inserts variables as plain text. An embed parameter or request value that reaches SQL can close a quoted string:
{!-- Unsafe: ?entry_id=1' UNION SELECT ... breaks out of the quotes --}
{exp:query sql="SELECT title FROM exp_channel_titles WHERE entry_id = '{embed:entry_id}'"}
{!-- Safe: anything that isn't a whole number becomes 0, which matches nothing.
Always pass the parameter, even empty ({embed="…" entry_id=""}): when it isn't
passed at all, the modifier never runs (see "Using guards safely") --}
{exp:query sql="SELECT title FROM exp_channel_titles WHERE entry_id = '{embed:entry_id:integer default="0"}'"}…{/exp:query}
Use it on early-parsed values (embed parameters, {segment_N}, Mo' Variables' {get:...}). A value produced by another tag, such as {exp:request:get}, is only resolved inside that tag's own output, so check it there.
Outputs a list of whole numbers, such as entry IDs, only when every item is one. For SQL IN () lists and EE parameters like entry_id="1|2|3".
{exp:channel:entries entry_id="{get:ids:integer_list default='-1'}"} 1|2|3, or -1 (matches nothing)
WHERE entry_id IN ({get:ids:integer_list output_separator="," default="0"}) 1,2,3, or 0
{get:ids:integer_list invalid="drop" max_items="50" unique="yes"}
| Parameter | Default | Effect |
|---|---|---|
separator |
|, |
Characters that separate items in the input (any of them) |
output_separator |
| |
What goes between items in the output. Use , for SQL |
quote |
none | single or double wraps each item in quotes: '1','2','3' |
invalid |
reject | drop leaves out bad items instead of rejecting the whole list |
max_items |
none | More items than this gives the fallback |
unique |
no | yes removes repeated numbers |
unsigned, min, max |
As :integer, applied to each item |
- By default one bad item rejects the whole list, so
1|2' OR 1=1gives the fallback. - Empty items, from
1,,2or a trailing comma, are ignored. Each item is normalised as:integerdoes (007gives7). - If no valid items remain, the output is the fallback.
- In
entry_id=usedefault="-1", not0or empty: EE ignoresentry_id=""andentry_id="0"and lists every entry. See Using guards safely.
Outputs the value only when the whole of it is a decimal number: digits with an optional sign and one full stop.
{get:max_price:decimal}
{get:price:decimal unsigned="yes" places="2" min="0.01" max="10000" default=""}
| Parameter | Default | Effect |
|---|---|---|
unsigned |
no | yes rejects negative numbers |
places |
none | The most decimal places allowed. More gives the fallback; nothing is rounded |
min, max |
none | Inclusive range, compared exactly with no floating-point rounding. A bound that isn't a decimal number is ignored |
- Thousands separators (
1,000), a comma as the decimal point (12,5), exponents (1e5),NaNandINFgive the fallback. - The output is normalised: no
+, no leading zeros, a0before a leading full stop, no trailing full stop (007.50gives7.50,.5gives0.5). Trailing zeros after the point are kept.
Outputs the value only when it is one of a list of allowed values. The output is the allowed value as written in the list, not the input, so with the default case-insensitive match TITLE gives title.
This is the safe way to let a request choose an SQL column or sort direction, which can't be put in quotes:
{!-- The page passes the request values to an embed, so they always exist (see Using guards safely) --}
{embed="products/.sorted" sort="{get:sort}" dir="{get:dir}"}
{!-- products/.sorted --}
{exp:query sql="SELECT title FROM exp_channel_titles
ORDER BY {embed:sort:one_of values='title|entry_date' default='entry_date'}
{embed:dir:one_of values='asc|desc' default='desc'}"}…{/exp:query}
{exp:channel:entries orderby="{get:sort:one_of values='title|date' default='date'}"}
| Parameter | Default | Effect |
|---|---|---|
values |
none | The allowed values. With no list, everything gives the fallback |
values_separator |
| |
Characters that separate the allowed values, such as , for values="small, medium, large" |
case_sensitive |
no | yes means Title doesn't match title |
For several choices at once, use :one_of_list.
Outputs a list of choices only when every item is one of the allowed values: :one_of for several values at once, such as colours, categories or statuses picked in a filter form. Each item is output as written in the allowed list, so nothing from the request reaches the output, and quote="single" makes a list ready for SQL.
{!-- The page: ?colours=red,BLUE --}
{embed="products/.by_colour" colours="{get:colours}"}
{!-- products/.by_colour: the list becomes 'red','blue'; skipped if empty or not allowed.
The page always passes colours=, so the {if} can be decided before the query runs --}
{if "{embed:colours:one_of_list values='red|green|blue'}"}
{exp:query sql="SELECT … WHERE colour IN ({embed:colours:one_of_list values='red|green|blue' output_separator=',' quote='single'})"}…{/exp:query}
{/if}
{exp:channel:entries status="{get:status:one_of_list values='open|featured' default='open'}"}
| Parameter | Default | Effect |
|---|---|---|
values |
none | The allowed values |
values_separator |
| |
Characters that separate the allowed values |
separator |
|, |
Characters that separate items in the input |
output_separator |
| |
What goes between items in the output |
quote |
none | single or double wraps each item in quotes. A quote character inside a listed value is doubled, as SQL expects ('it''s') |
invalid |
reject | drop leaves out items that aren't allowed instead of rejecting the whole list |
max_items |
none | More items than this gives the fallback |
unique |
no | yes removes repeated choices |
case_sensitive |
no | yes means Red doesn't match red |
Outputs the value only when it is a URL slug: letters, digits, hyphens and underscores. Unlike EE's :url_slug, which turns any text into a slug, this rejects anything that isn't one already, so a segment or request value can be trusted in a URL, a parameter or a quoted SQL string.
{if "{segment_2:slug}"}{exp:channel:entries url_title="{segment_2:slug}"}…{/exp:channel:entries}{/if}
{segment_3:slug lowercase="yes" max_length="200"}
{segment_4:slug dots="yes"} file.pdf
| Parameter | Default | Effect |
|---|---|---|
lowercase |
no | yes rejects capital letters |
dots |
no | yes also allows full stops between characters (file.pdf), but not two in a row or at either end, so .. can't get through |
Accented letters (café) give the fallback.
Outputs the value only when it is a real date in the expected format. 2026-02-30 is rejected, not rolled over to 2 March.
{get:from:date} 2026-11-30, or nothing
{get:from:date input_format="d/m/Y" output_format="Y-m-d"} 30/11/2026 gives 2026-11-30
{get:from:date min="2020-01-01" max="today" default=""}
| Parameter | Default | Effect |
|---|---|---|
input_format |
Y-m-d |
The format the value must match exactly, in PHP date() letters |
output_format |
as given | Reformat the output, such as Y-m-d for SQL |
min, max |
none | Inclusive range, written in input_format, or today. A bound that isn't a valid date is ignored |
- Times work too:
input_format="Y-m-d H:i". Values are checked as written, with no time zone conversion;todayis midnight UTC. - The parameters aren't called
format, because EE treats{var format="..."}as a date variable.
Outputs the value only when it is an email address.
{get:email:email}
{exp:query sql="SELECT member_id FROM exp_members WHERE email = '{embed:email:email}'"}
<input type="email" name="email" value="{embed:email:email}">
| Parameter | Default | Effect |
|---|---|---|
rfc |
no | yes accepts every address PHP's validator accepts, including o'[email protected]. The output is HTML-encoded (o'[email protected], braces as {), so it displays correctly and is safe in attributes, but it is not a SQL guard: escape it properly for SQL. |
By default the check is strict: letters, digits and . _ % + - before the @, and a domain of letters, digits and hyphens with at least one dot. That keeps out quotes, apostrophes, backslashes, spaces, angle brackets and braces, so the output is safe inside a quoted SQL string or an HTML attribute.
The trade-off: a valid address with an apostrophe, such as o'[email protected], gets the fallback. If you need those addresses, use rfc="yes".
Outputs the value only when it is a well-formed http or https URL, so a link or redirect taken from a parameter or the request can go into an href.
<a href="{embed:link:safe_url default='/'}">More</a>
{get:return:safe_url relative="yes" domains="example.com|*.example.com" default="/"}
| Parameter | Default | Effect |
|---|---|---|
schemes |
http|https |
Allowed schemes |
relative |
no | yes also allows paths on this site starting with a single / (/shop?page=2). Without it, a path gives the fallback |
domains |
any | Only these hosts. *.example.com matches subdomains, but not example.com itself; list both if you want both. Relative paths aren't affected |
Rejected:
javascript:,data:and every other scheme not inschemes, in any case and even when entity-encoded (javascript:).- Protocol-relative
//evil.com, and/\evil.com, which browsers treat the same way. - A user name or password (
https://[email protected]goes toevil.com). - Characters a URL can't contain unencoded: spaces, quotes (including
'),<>, backslashes and braces, plus broken%escapes. That also makes the output safe inside a quoted attribute. - Hosts with accented letters; use the
xn--form.
Entities are decoded first, so & in a query string is output as &.
Outputs the value only when it is a UUID (8-4-4-4-12 hex digits). The output is lower case.
{get:token:uuid}
{segment_3:uuid version="4"}
| Parameter | Default | Effect |
|---|---|---|
version |
any | Only this UUID version (1 to 8) |
Braces and the 32-digit form without hyphens give the fallback.
Outputs the value only when it is a hex colour: 3 or 6 hex digits, with or without #. The output is lower case with a #, ready for a style attribute.
<div style="background: {embed:bg:hex_color default='#ffffff'}">
{get:c:hex_color alpha="yes" hash="no"}
| Parameter | Default | Effect |
|---|---|---|
alpha |
no | yes also allows 4- and 8-digit colours with transparency |
hash |
yes | no outputs without the # |
Outputs the value only when it is an IPv4 or IPv6 address.
{embed:server:ip version="4" public="yes"}
| Parameter | Default | Effect |
|---|---|---|
version |
either | 4 or 6 for only that kind |
public |
no | yes rejects private and reserved ranges (10.x, 192.168.x, 127.x, ::1 and so on) |
Outputs the value only when every character is one of the allowed kinds. A flexible guard for search terms, references, codes and names.
{get:q:charset allow="alpha|digits|space" max_length="50"}
{get:ref:charset allow="alnum|dash" min_length="6" max_length="12"}
{embed:name:charset allow="alpha|space|dash" extra="'" unicode="yes"}
| Parameter | Default | Effect |
|---|---|---|
allow |
none | Kinds of character: alpha (A–Z, a–z), digits (0–9), alnum (both), space (the space character only, not tabs or new lines), dash, underscore, dot, comma. With none, everything gives the fallback |
extra |
none | Other characters to allow, written out: extra="'" or extra="@+". Allowing quotes, < > or braces makes the output unsafe in SQL, HTML or templates |
unicode |
no | yes lets alpha include accented and non-Latin letters (é, ß, Ж) and digits include other scripts' digits |
Outputs the value only when it is valid base64. The value is passed through as it is, not decoded.
{get:token:base64}
{segment_3:base64 url_safe="yes"}
| Parameter | Default | Effect |
|---|---|---|
url_safe |
no | yes uses the URL-safe alphabet (- and _ instead of + and /), with the = padding optional |
Use url_safe for values in URLs: a + in a query string arrives as a space.
Turns a yes/no word into yes or no. y, yes, true, 1 and on give yes; n, no, false, 0 and off give no (any case). Anything else gives the fallback. For feeding request values into EE's yes/no parameters.
{exp:channel:entries show_future_entries="{get:future:yes_no default='no'}"}
{get:sale:yes_no true="1" false="0"}
| Parameter | Default | Effect |
|---|---|---|
true |
yes |
Output for a yes word |
false |
no |
Output for a no word |
Outputs yes when the value is y, yes, true, 1 or on (any case); anything else, including empty values, gives the fallback. :is_false is the mirror: yes for n, no, false, 0 or off.
{if "{get:sale:is_true}"}<p>Sale prices shown</p>{/if}
{if "{embed:show_price:is_false}"}<p>Call for price</p>{/if}
{embed:show_price:is_true output="1" default="0"}
| Parameter | Default | Effect |
|---|---|---|
output |
yes |
What to output when the value matches |
Outputs the value only when it has visible content. Also available as :has_content.
A rich-text field an editor has cleared often still holds <p> </p> or <p><br></p>, which EE treats as content, so {if body} is true and an empty box appears. :not_empty treats as empty: whitespace (including and zero-width characters), empty tags and HTML comments. The value itself is output unchanged.
{if "{body:not_empty}"}<section>{body}</section>{/if}
{if "{body:not_empty}" == ""}<p>Coming soon.</p>{/if}
{summary:not_empty default="No summary yet"}
| Parameter | Default | Effect |
|---|---|---|
default |
empty | Output when the value is empty |
html |
yes | no doesn't strip tags; only whitespace and count as empty |
allow |
img|iframe|video|audio|object|embed|svg|canvas |
Tags that count as content on their own, so an image-only field isn't empty. allow="" means none |
Outputs the value, or the value parameter when it is empty or only whitespace (including ). Markup is not stripped, so it suits plain-text fields and parameters; for rich text use :not_empty with default, or add html="yes".
{embed:limit:fallback value="10"}
{meta_title:fallback value="{title}"}
| Parameter | Default | Effect |
|---|---|---|
value |
empty | Output when the value is empty (default also works) |
html |
no | yes also treats empty tags and comments as empty, like :not_empty |
allow |
as :not_empty |
With html="yes", tags that count as content on their own |
Removes HTML tags, leaving the text. For meta descriptions, plain-text excerpts and alt text.
<meta name="description" content="{body:strip_tags:attr_safe}">
{body:strip_tags allow="em|strong"}
| Parameter | Default | Effect |
|---|---|---|
allow |
none | Tags to keep, such as em|strong|a. Kept tags lose their attributes |
keep_attributes |
no | yes keeps kept tags' attributes. Only for trusted content: attributes can carry JavaScript (onclick, href="javascript:...") |
collapse |
yes | no keeps the original spacing. By default runs of whitespace become one space and the ends are trimmed |
How it differs from PHP's strip_tags() and EE's :limit:
- Text after a bare
<survives:x <3 ystays as it is. - The contents of
script,style,templateandnoscriptelements are removed, not left as text. - Block tags and line breaks become spaces, so
<p>One</p><p>Two</p>givesOne Two, notOneTwo. - Entities such as
&are left as they are, so the output is still HTML text.
Picks an item at random from a list held in the variable.
{embed:taglines:random} one of "Fast|Friendly|Free"
{hero_images:random separator=","}
{related_ids:random count="3"} three different items, in random order
| Parameter | Default | Effect |
|---|---|---|
separator |
| |
Characters that separate items |
count |
1 | How many items to pick. Items aren't repeated, so a count larger than the list gives the whole list, shuffled |
output_separator |
| |
What goes between picked items |
quote |
none | single or double wraps each item in quotes |
- Empty items are ignored; an empty list gives an empty string.
- Cached output stays the same until the cache expires: template caching, tag caching (
cache="yes") and static page caches all freeze the pick.
Shortens text to a number of words, adding … when it cuts. HTML tags are removed first, because cutting HTML part-way would leave tags unclosed. EE's own :limit cuts by characters instead.
{summary:word_limit words="30"}
{body:word_limit words="50" end=" [more]"}
| Parameter | Default | Effect |
|---|---|---|
words |
30 | How many words to keep |
end |
… |
Added when the text was cut. Write a leading space as   |
Counts the words, ignoring HTML tags, or gives a reading time. A word is a run of letters and digits in any script, which may contain apostrophes and hyphens (don't, well-known).
{body:word_count} words
{body:word_count per_minute="200"} min read
| Parameter | Default | Effect |
|---|---|---|
per_minute |
none | Give minutes to read at this many words a minute instead, rounded up, at least 1 |
Part of the text, by character position. It counts characters, not bytes, and an entity such as & counts as one, so nothing is cut in half. For text with tags, chain :strip_tags first.
{title:substr length="1"} first letter, for A–Z indexes
{code:substr start="-4"} last four characters
| Parameter | Default | Effect |
|---|---|---|
start |
0 | Where to start; negative counts from the end |
length |
the rest | How many characters; negative leaves that many off the end |
Wraps search words in <mark>, for search results. Matching ignores case and works in any script. Only text is searched, so a search for href doesn't break links, and the marked text comes from the value itself, so a phrase from the request can't add HTML.
{title:highlight phrase="{get:q}"}
{excerpt:highlight phrase="{embed:keywords}" tag="strong" class="hit"}
{title:highlight phrase="red lamp" exact="yes"}
| Parameter | Default | Effect |
|---|---|---|
phrase |
none | What to highlight. Each word is highlighted separately |
exact |
no | yes highlights only the whole phrase |
min_letters |
2 | Shorter words in the phrase are ignored |
tag |
mark |
mark, strong, em, b or span |
class |
none | A class for the tag |
Turns line breaks into <br>, for plain text shown as HTML, such as addresses. The text is escaped first (&, <, >, quotes, and braces as {), because plain text isn't HTML.
{address:nl2br}
{notes:nl2br escape="no" xhtml="yes"}
| Parameter | Default | Effect |
|---|---|---|
escape |
yes | no when the value is already HTML |
xhtml |
no | yes writes <br /> |
Adds target="_blank", rel="noopener noreferrer" and optionally a class to links that go to other sites, for rich-text fields. A link is external when its href is an http(s) or // URL whose host isn't this site: the site URL's host in EE, plus any domains. Existing target attributes are kept; rel and class values are added to any already there.
{body:external_links}
{body:external_links class="external" domains="shop.example.com|*.example.com"}
{body:external_links target="" rel="nofollow"}
| Parameter | Default | Effect |
|---|---|---|
target |
_blank |
target="" adds none |
rel |
noopener noreferrer |
rel="" adds none |
class |
none | A class to add |
domains |
none | More hosts that count as this site. *.example.com matches subdomains |
Hides email addresses from simple scrapers by writing each character as an HTML entity. Browsers show and follow the addresses as normal. Addresses in text and in mailto: links are both encoded, with no JavaScript. It deters simple harvesters, not determined ones.
{body:encode_email}
{contact_text:encode_email link="yes"}
| Parameter | Default | Effect |
|---|---|---|
link |
no | yes also turns addresses in text (not already in a link) into mailto: links |
The case formatters handle accented and non-Latin letters (éclair gives Éclair). They change only text: HTML tags, entities and {variables} are left exactly as they are, so links, & and {filedir_1} survive :uppercase.
{title:lowercase} "Café ÉCLAIR" gives "café éclair"
{title:uppercase} "Fish & chips" gives "FISH & CHIPS"
Uppercases the first letter. Leading spaces, quotes and other punctuation are skipped; if the text starts with a digit, nothing changes.
{excerpt:ucfirst} "“hello world" gives "“Hello world"
{title:ucfirst force="yes"} "HELLO World" gives "Hello world"
| Parameter | Default | Effect |
|---|---|---|
force |
no | yes lowercases the rest first |
Uppercases the first letter of each word. By default the rest of each word is left alone, so UK and iPhone's later capitals survive. A word starts after a space, hyphen, dash, slash, or opening bracket or quote; apostrophes don't start a word (o'neil gives O'neil).
{title:title_case} "free UK delivery" gives "Free UK Delivery"
{title:title_case force="yes"} "BIG SUMMER SALE" gives "Big Summer Sale"
{title:title_case small_words="yes"} "the lord of the rings" gives "The Lord of the Rings"
| Parameter | Default | Effect |
|---|---|---|
force |
no | yes lowercases the text first |
small_words |
no | yes keeps a, an, and, as, at, but, by, for, from, in, into, nor, of, on, or, the, to, vs and with in lower case, except as the first word or after : . ! ? |
Lowercases the text, then uppercases the first letter of each sentence. A sentence starts at the beginning, after ., ! or ? followed by a space or line break, and at a paragraph, heading or list item.
{title:sentence_case} "BIG NEWS. WE'RE OPEN!" gives "Big news. We're open!"
{body:sentence_case force="no"} "hello. Visit the UK." gives "Hello. Visit the UK."
| Parameter | Default | Effect |
|---|---|---|
force |
yes | no keeps existing capitals and only fixes sentence starts |
Lowercasing loses the capitals in names, acronyms and "I"; use force="no" where that matters.
Pads text to a length, by default with zeros on the left. Longer text is left as it is.
{order_id:pad length="6"} 42 gives 000042
{name:pad length="10" char="." side="right"} "Tea" gives "Tea......."
| Parameter | Default | Effect |
|---|---|---|
length |
none | The length to pad to, in characters |
char |
0 |
The padding character(s) |
side |
left |
left, right or both |
Writes a whole number from 1 to 3999 in Roman numerals; anything else is left as it is.
{count:roman} 4 gives IV
{chapter:roman lowercase="yes"} 9 gives ix
| Parameter | Default | Effect |
|---|---|---|
lowercase |
no | yes for lower-case numerals |
A hash of the value as lower-case hex, for cache keys, Gravatar URLs and anonymous IDs. Not for passwords.
https://gravatar.com/avatar/{email:hash trim="yes" lowercase="yes"}
{entry_id:hash algo="md5" length="8"}
| Parameter | Default | Effect |
|---|---|---|
algo |
sha256 |
Any algorithm PHP's hash() supports: sha1, md5, sha512, crc32b … An unknown one gives an empty string |
trim |
no | yes trims spaces first |
lowercase |
no | yes lowercases first |
length |
all | Keep only this many characters |
Encodes the value as base64.
{entry_id:base64_encode url_safe="yes"}
| Parameter | Default | Effect |
|---|---|---|
url_safe |
no | yes uses - and _ instead of + and /, without = padding, for URLs |
:base64_decode decodes it again. Invalid base64 gives default (empty unless set). Decoding can produce anything, including HTML and EE tags, so the result is escaped by default: &, <, > and quotes become entities, and braces become { }. Add raw="yes" only for values you encoded yourself. It also takes url_safe.
{get:msg:base64_decode url_safe="yes"}
Guards fail closed: a bad value becomes the fallback, so nothing can be injected. Two things in ExpressionEngine itself can still leave a template broken or too open.
EE only runs a modifier on a variable that exists. If ?sort isn't in the URL, Mo' Variables doesn't define {get:sort}; if an embed doesn't pass entry_id=, there is no {embed:entry_id}. The modifier is never called, so default is not applied.
What happens next depends on the kind of variable:
| Variable | When it's missing | Safe pattern |
|---|---|---|
| Embed parameter | EE removes the tag, so it outputs nothing, but too late for an {if} around tags |
Always pass the parameter, even empty: {embed="…" entry_id=""} makes {embed:entry_id:integer default="0"} give 0. An {if} then works too |
{segment_N} |
Always exists (empty when absent) | Guards and default work as normal |
Another add-on's variable, such as Mo' Variables' {get:…} |
The tag is left unparsed | Pass it into an embed parameter and guard it there (below) |
An {if} doesn't protect tags from a missing variable. EE can't decide a condition that contains an undefined variable in its early pass, so it parses the tags inside first, and the {if} only hides their output. This applies to add-on variables such as {get:…} and to embed parameters that weren't passed: {if "{embed:q}"} around an {exp:query} still runs the query when the embed has no q=. With an unparsed {get:…} or an empty value in its SQL, the query can error. An {if} protects tags only when the variable always exists: an embed parameter that is always passed (even as ""), a {segment_N}, or a Mo' Variables value with a default.
Pass the value to an embed instead, and always pass the parameter. It then always exists, empty when the request value is missing, so the modifier runs and default applies:
{!-- The page --}
{embed="products/.list" sort="{get:sort}"}
{!-- products/.list --}
{exp:query sql="SELECT title FROM exp_channel_titles
ORDER BY {embed:sort:one_of values='title|entry_date' default='entry_date'}"}…{/exp:query}
Tested on EE 7.5.28 with :one_of_list feeding a query: with the request value missing, valid, and an injection attempt, the page renders without an SQL error each time. Give embed parameters names that don't start with each other's names (see Known issues).
Channel entries parameters are more forgiving. In testing, orderby="{get:sort:one_of …}" with ?sort missing was ignored and the tag used its default order. Check other parameters before relying on that.
An empty parameter usually means "no filter". For guards feeding tag parameters, that turns a rejected value into "everything":
| Parameter | Ignored, so every entry is listed | Matches nothing |
|---|---|---|
entry_id= |
"" and "0" |
"-1" |
url_title= |
"" |
wrap in {if} |
{exp:channel:entries entry_id="{get:ids:integer_list default='-1'}" dynamic="no"}
{if "{segment_2:slug}"}{exp:channel:entries url_title="{segment_2:slug}"}…{/exp:channel:entries}{/if}
For any other parameter, check what an empty value does before relying on a guard's fallback, or wrap the tag in {if}.
In ExpressionEngine 7.5.28 and probably earlier, early-parsed variables with a modifier can get the wrong value when one variable's name starts with another's. With {embed:body} and {embed:body2} in the same template, {embed:body2:not_empty} may output body's value instead.
This affects every modifier, EE's own included ({embed:body2:limit characters="3"} does the same), and any early-parsed variable: embed parameters, {segment_1} versus {segment_10}, layout variables and global variables. The cause is in EE's LegacyParser::parseModifiedVariables(): it looks for {embed:body…} and doesn't check that the name stops there.
It's reported to EE as ExpressionEngine#5493, and it's still present in EE 7.6.0. Until EE fixes it, avoid giving early-parsed variables names that start with another variable's name when you use modifiers on them, for example body_main and body_extra rather than body and body2.
ExpressionEngine 7.3 or later (7.3.0 added add-on variable modifiers and chaining). PHP 7.4+, with the mbstring extension for non-Latin text.
composer install
composer test
The tests run without ExpressionEngine: tests/stubs stands in for EE's ModifierInterface. See CONTRIBUTING.md for adding a modifier.
MIT. See LICENSE.