# Building Reusable Template Sections

## Component Templates Tutorial

### The Scenario: Sending a Welcome Packet to New Employees

Imagine you work in HR. Every time someone is hired, you send a Welcome Packet. But not everyone gets the same packet.

* **Situation A** - John is hired in the Sales department.\
  He should receive the **Sales Welcome Section**.
* **Situation B** - Maria is hired in Engineering.\
  She should receive the **Engineering Welcome Section**.
* **Situation C** - Emily is a Remote employee.\
  She should also receive the **Remote Work Policy Section**.

**The Old Way:** You create different templates to address each team which would be hard to maintain and easy to pick wrong one. Example:

* Sales Welcome Template
* Engineering Welcome Template
* Sales + Remote Policy Template
* Engineering + Remote Policy Template

***

### The S-Docs Way

**You create One Parent Template and** + **Small Reusable Components**

The parent decides what to include.

***

{% stepper %}
{% step %}
**Step 1: Create the Parent Template**

This is your main Welcome Packet.

Example:

```
<h1>Welcome to the Company!</h1>
<p>We are excited to have you join us.</p>
```

This part never changes.
{% endstep %}

{% step %}
**Step 2: Create Simple Components**

Now create small reusable sections.

Template Format → **Component**

**Component 1: Sales Welcome Section**

```
<h2>Welcome to the Sales Team!</h2>
<p>You will be working with leads, clients, and revenue targets.</p>
```

**Component 2: Engineering Welcome Section**

```
<h2>Welcome to Engineering!</h2>
<p>You will be building and maintaining our product systems.</p>
```

**Component 3: Remote Work Policy Section**

```
<h2>Remote Work Policy</h2>
<p>Review the remote work guidelines and equipment policy.</p>
```

Each of these is a standard Component template.
{% endstep %}

{% step %}
**Step 3: Insert Components into Parent**

Now inside the Parent Template, add a Component Merge Field where the section should appear.

**Static component**

```
{{{{!Sales Welcome Section}}}}
```

That inserts the component named `Sales Welcome Section`.

**Department-Based Dynamic Component**

Let’s assume we have a field:

```
Employee.Department__c
```

It contains either:

* Sales
* Engineering

Now we write:

```
{{{{!Welcome {{!Employee.Department__c}} Section}}}}
```

What happens?

If Department = Sales\
→ It loads: **Welcome Sales Section**

If Department = Engineering\
→ It loads: **Welcome Engineering Section**

That’s dynamic components in the simplest form.
{% endstep %}

{% step %}
**Step 4: Adding the Remote Policy Only If Needed**

Now we check:

If Employee.Remote\_\_c = TRUE

We add the Remote Work Policy Section.

```
<!--RENDER={{!Employee.Remote__c}} == true -->
{{{{!Remote Work Policy Section}}}}
<!--ENDRENDER-->
```

Now:

Remote employee → section is included\
Office employee → section is skipped
{% endstep %}
{% endstepper %}

***

## What Just Happened?

You built:

* 1 Parent Template
* 3 Small Components

And parent template decides what to include.

No duplicate templates.\
No manual decisions.\
No errors.

***

## Even Simpler Model

Think of it like this:

Parent Template = Table of Contents\
Components = Chapters

The parent says:

* Always include Chapter 1
* Include Chapter 2 if Sales
* Include Chapter 3 if Engineering
* Include the remote policy section if Remote

That’s it.

***

## When Should You Use Components?

Use them when:

* A section repeats across templates
* A section is large (legal, pricing, policy)
* A section may appear conditionally
* You want cleaner, more readable parent templates

***

## When NOT to Use Components

Don’t use a component for:

* A single line of text
* Tiny conditional phrases
* One-time content

Components are for **sections**, not single sentences.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.sdocs.com/quick-start/template-building/component-templates-tutorial.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
