Nested Spintax

How nesting transforms flat spinning into a powerful template engine — and why the Spintax.Net approach is the standard.

What is Nested Spintax?

Regular spintax picks a random option from a list: {red|blue|green} produces one of three colors. Nested spintax places spintax inside spintax — like a matryoshka doll, where each layer reveals more variation inside.

When the engine encounters nested structures, it resolves from the innermost expression outward. The inner braces are evaluated first, and their result becomes part of the outer expression.

{red|{dark|light} blue} car

Here {dark|light} resolves first (e.g. dark), producing {red|dark blue}. Then the outer enumeration picks one option: red or dark blue.

Why Nesting Matters

Without nesting, your options are flat. Three enumerations with three options each give you 3 + 3 + 3 = 9 fragments. With nesting, the same elements combine multiplicatively: 3 × 3 × 3 = 27 unique variants from a single compact template.

This exponential growth is the key to generating truly unique content. A moderately complex template with nested enumerations and permutations can produce thousands or millions of distinct outputs — all from one carefully crafted source.

Common Limitations of Other Tools

Most spintax tools handle only the basics. Here is what typically goes wrong:

  • Enum-in-enum only — they support {a|{b|c}} but nothing else. No permutations, no variables, no includes inside other elements.
  • Depth limits — many parsers break after 2–3 levels of nesting, silently producing corrupted output.
  • No cleanup — after resolving nested structures, spacing collapses, punctuation doubles, capitalization breaks. The result needs manual editing.
  • No composability — without variables and includes, every template is an island. Reusing common blocks means copy-pasting.

The Spintax.Net Approach

Spintax.Net implements nesting as a first-class feature, not an afterthought. Five design decisions make it work:

  1. Arbitrary depth — there is no nesting limit. Ten levels deep works the same as two.
  2. Cross-element nesting — enumerations inside permutations, permutations inside enumerations, variables containing nested structures, includes embedding entire nested templates. Any element inside any other.
  3. Innermost-first resolution — the engine always resolves from the deepest level outward. This makes evaluation predictable and debuggable.
  4. Smart post-processing — after all nesting is resolved, the engine automatically fixes capitalization, collapses duplicate spaces, corrects punctuation spacing, and handles sentence boundaries. The output is clean text, not raw concatenation.
  5. Safety — circular reference detection for #include prevents infinite loops. Variable scope rules (runtime > local > global) prevent accidental overwrites.

From Simple to Advanced

1. Enum inside enum

{{premium|luxury} sedan|{compact|mid-size} SUV}

Inner enumerations resolve first, then the outer one picks a result. Possible outputs: premium sedan, luxury sedan, compact SUV, mid-size SUV.

2. Enum inside permutation

[<minsize=2;maxsize=3;sep=", ";lastsep=" and "> {red|blue} apples|{big|small} oranges|bananas]

Each permutation element contains its own enumeration. The engine resolves inner enumerations first, then shuffles and joins. Example output: blue apples, bananas and small oranges.

3. Variables with nested spintax

#set %product% = {{premium|budget} {laptop|tablet}|{smart|classic} phone}
#set %action% = {Buy|Get|Order}

%action% your new %product% today!

Variables store nested spintax and resolve each time they are referenced. Combined with multiple variables, the variant count multiplies rapidly.

4. Includes with nesting

/#  main template  #/
#include "hero-text"

{Check out|Discover|Explore} our [<, > features|plans|pricing].

The included template can itself contain enumerations, permutations, variables, and even further includes. Circular reference detection keeps everything safe.

AI + Nested Spintax

Large language models are excellent at writing complex nested templates. A single prompt can produce a template with multiple nesting levels, conditional blocks via variables, and reusable sections via includes.

The workflow is simple: use AI to create the template once, then use Spintax to generate unique variants cheaply forever. One API call to create the template. Zero API calls to generate each variant. Nested spintax is what makes this economically viable — the deeper the nesting, the more unique outputs per template.

Getting Started

Ready to use nested spintax in your projects? Start with the syntax reference for the complete specification, or try the Spintax WordPress plugin to see nesting in action.