SmartBlocks

Every site accumulates content that gets pasted in more than one place: the footer call-to-action, the legal disclaimer, the "upgrade your membership" box, the course-card layout that appears on six landing pages. Paste it forty times and you own forty copies, and the next edit means hunting thirty-nine of them down. The ones you miss stay wrong in public.

A SmartBlock is the fix: content you write once and insert anywhere. The block lives in its own library in the WordPress admin, under SmartBlocks, with no front-end page of its own. When you edit the block, every insertion on every page updates. One edit, forty locations, done.

Your block gets its own shortcode

Publish a block called footer_cta and Torii automatically registers a shortcode for it:

[memb_smartblock_footer_cta]

Use it like any other shortcode, in pages, widgets, templates, anywhere shortcodes go. There's also a generic form that selects the block by ID or slug:

[memb_smartblock blockid="footer_cta"]

And a Gutenberg block, for inserting SmartBlocks from the editor without typing anything.

Keep slugs simple: lowercase letters, numbers, underscores. The slug becomes a shortcode name, and WordPress handles plain names like these most reliably. footer_cta over the-footer-call-to-action-block.

Attributes make blocks dynamic

A block that renders identically everywhere is useful. A block that adapts to each insertion is where this feature earns its keep.

Inside a block, {{atts:key}} tokens mark places where values should go. When the block is inserted, the attributes you pass fill the tokens:

[memb_smartblock_greeting name="Dana"]

renders a block whose content is Hello, {{atts:name}} as Hello, Dana. Tokens that don't receive a value are removed from the output rather than left visible, so a missing attribute degrades quietly instead of printing {{atts:whatever}} at your members.

The rules for attributes

  • Names are lowercase, no spaces. Keep them short but descriptive: name, img, salesurl.
  • Values containing spaces need quotes. Single or double both work.
  • If the shortcode itself sits inside quoted markup, alternate the quote style inside so the parser can tell where things end.
  • A literal quote inside a value is written ".

A worked example: the course card

The pattern that shows what parameterized blocks are for: a course card that looks normal to members with access and grayed out to everyone else, each linking where it should.

The block, call it coursecard, holds the layout plus an access conditional:

[memb_is_logged_in]
<a href="{{atts:pageurl}}"><img src="{{atts:img}}" alt="{{atts:desc}}"></a>
[else_memb_is_logged_in]
<a href="{{atts:salesurl}}" class="ghosted"><img src="{{atts:img}}" alt="{{atts:desc}}"></a>
[/memb_is_logged_in]

Each insertion is one line that says what this particular card is:

[memb_smartblock_coursecard desc="Crafting a Clear Message" img="/uploads/clear-message.jpg" pageurl="/courses/clear-message/" salesurl="/buy/clear-message/"]

Six landing pages, six one-line insertions, one layout to maintain. When the design changes, the block changes, and all six cards follow. (The ghosted class is yours: a CSS filter that grays the image out.)

Nesting

A block can contain any shortcode, Torii's, WordPress's, or another SmartBlock. That's the nesting that makes the course-card pattern work: the block holds the conditional, the insertion supplies the values.

A note on PHP

SmartBlocks can evaluate embedded PHP when the code evaluation layer is enabled on your site. It's a power-user door: convenient for a computed value in a block, and a liability in the hands of anyone who can edit blocks, because they can run code. Most sites never need it; the attribute system covers the dynamic cases. If you do enable it, treat editing rights on SmartBlocks the way you'd treat plugin editing rights.

SmartBlocks vs. Shortcode Templates

They sit at different layers. Shortcode Templates change how Torii's own shortcodes render: you take over the HTML of the login form, the directory grid. SmartBlocks are your content, packaged for reuse: the layout is yours to begin with, and the block system just makes it insertable and parameterized. If you're restyling something Torii renders, you want templates. If you're repeating something you wrote, you want a SmartBlock.

Where they shine

  • Repeated boilerplate: disclaimers, support hours, address blocks. One edit propagates everywhere.
  • Parameterized CTAs: same design, different offer per page, driven by attributes.
  • Member-aware fragments: wrap the block's content in [memb_is_logged_in] or tag conditionals and the same insertion shows different things to different members.
  • Layout modules for landing pages: the course-card pattern above, generalized to anything you repeat.