Lesson 08 of 10

Advanced Features

Unlock OrbLayout's full power with markdown blocks, {{#with}} scoping, partials, component imports, :class directives, and more.

Markdown Blocks

Write content in markdown directly inside your .orb files. OrbLayout converts it to HTML at build time.

Input (.orb) .orb
<markdown>
# Hello World

This is **bold** and *italic*.

- Item one
- Item two
- Item three

[Visit OrbLayout](https://github.com
/rukkit-official/orblayout)

---

Here's some `inline code`.
</markdown>
Output (HTML) html
<h1>Hello World</h1>

<p>This is <strong>bold</strong>
and <em>italic</em>.</p>

<ul>
  <li>Item one</li>
  <li>Item two</li>
  <li>Item three</li>
</ul>

<a href="...">Visit</a>

<hr>

<p>Here's <code>inline</code>.</p>

Supported markdown syntax

MarkdownHTML Output
# Heading<h1>
## Heading<h2>
### Heading<h3>
**bold**<strong>
*italic*<em>
`code`<code>
[text](url)<a href>
![alt](src)<img>
- item<ul><li>
---<hr>
๐Ÿ’ก

Perfect for: Blog posts, documentation pages, changelog sections โ€” anywhere you want to write content quickly without HTML tags.

{{#with}} โ€” Scoping Variables

{{#with}} lets you "enter" a nested object so you can reference its properties directly.

Without {{#with}} โ€” verbose .orb
<!-- You'd need dot notation (which OrbLayout doesn't support) -->
<!-- So without {{#with}}, you can't access nested data easily -->
With {{#with}} โ€” clean! .orb
<script data>
({
  author: {
    name: "Dan",
    bio: "Full-stack developer & OrbLayout creator",
    twitter: "@dan_dev",
    avatar: "/assets/dan.jpg"
  }
})
</script>

<div class="author-card">
  {{#with author}}
    <img src="{{ avatar }}" alt="{{ name }}" />
    <h3>{{ name }}</h3>
    <p>{{ bio }}</p>
    <a href="https://twitter.com/{{ twitter }}">Follow</a>
  {{/with}}
</div>

Inside {{#with author}}, variables like {{ name }} automatically refer to author.name.

Partials โ€” Simple File Includes

Partials let you include another .orb file as-is, without props. Think of it as a simple HTML include.

components/analytics.orb .orb
<!-- Google Analytics snippet -->
<script async
  src="https://gtag...">
</script>
<script>
  window.dataLayer = ...
</script>
layouts/main.layout .layout
<head>
  ...
  <use partial="analytics" />
</head>

Components vs Partials

FeatureComponentPartial
Syntax<use component="..." /><use partial="..." />
Propsโœ… Yes โ€” pass data via attributesโŒ No โ€” inserted as-is
Use caseDynamic UI blocks (cards, heroes)Static snippets (analytics, meta tags)

:class Directives

Conditionally apply CSS classes based on data values. Similar to Vue.js's :class binding.

:class Directive .orb
<script data>
({
  isActive: true,
  isHidden: false,
  isDarkMode: true
})
</script>

<div class="card"
  :class="{ active: isActive, hidden: isHidden, dark: isDarkMode }">
  ...
</div>

<!-- Output: <div class="card active dark"> -->

Only classes with truthy conditions get applied. hidden doesn't appear because isHidden is false.

Advanced Styles

Style deduplication

If multiple components on a page have identical <style> blocks, OrbLayout only includes the CSS once:

Used 5 times on a page .orb
<!-- components/card.orb -->
<style>
.card { background: #fff; padding: 1rem; border-radius: 12px; }
</style>

<div class="card">...</div>

<!-- โœ… CSS is only included ONCE in <head>, not 5 times -->

Styles from multiple components

If your page uses card.orb, badge.orb, and hero.orb โ€” each with their own <style> โ€” all three CSS blocks are collected and injected into a single <style> tag in the page's <head>.

Combining Everything

Here's a page that uses every advanced feature together:

pages/showcase.orb .orb
<script data>
({
  title: "Advanced Showcase",
  showIntro: true,
  author: {
    name: "Dan",
    role: "Creator"
  },
  features: [
    { name: "Markdown", desc: "Write content faster" },
    { name: "Filters", desc: "Transform data inline" }
  ]
})
</script>

<import component="card" as="Card" />

<layout src="main.layout">
  <content>
    <h1>{{ title | uppercase }}</h1>

    {{#if showIntro}}
      <markdown>
## Welcome!
This page shows **every** advanced feature.
      </markdown>
    {{/if}}

    {{#with author}}
      <p>By {{ name }}, {{ role }}</p>
    {{/with}}

    {{#each features}}
      <Card title="{{ name }}" description="{{ desc }}" />
    {{/each}}

    <use partial="analytics" />

    <p>Built: {{ @page.date }}</p>
  </content>
</layout>

This single page uses: data blocks, imports, layouts, filters, conditionals, markdown, {{#with}} scoping, loops, components, partials, and built-in @page variables.

โœ… Lesson 8 Checkpoint

You should now be able to:

  1. Write inline markdown with <markdown> blocks
  2. Scope variables with {{#with object}}
  3. Include files with <use partial="..." />
  4. Conditionally add CSS classes with :class directives
  5. Understand how styles are deduplicated and collected
  6. Combine all features together in a single page