[Sugester V2 EN](https://sugester.intum.pl/kb/sugester-v2-en.md) / [CMS](https://sugester.intum.pl/kb/sugester-v2-en/cms.md)

# [Reusable sidebar - pattern](https://sugester.intum.pl/kb/sugester-v2-en/reusable-sidebar-pattern.md)

<p>When you have multiple subpages with the same sidebar (e.g., product features list), instead of copying HTML to each page, you can use a reusable paragraph.</p>

<h2>How it works</h2>

<p>Diagram:</p>
<div style="position: relative;"><pre class="language-text" tabindex="0"><code class="language-text">Layout                          Page
┌─────────────────────┐         ┌─────────────────────┐
│ {% if has_sidebar %}│         │ fields.has_sidebar  │
│   &lt;flex&gt;            │◄────────│ paragraph_codes     │
│     {{ paragraphs }}│         │ content (main)     │
│     {{ content }}   │         └─────────────────────┘
│   &lt;/flex&gt;           │                    │
│ {% endif %}         │                    ▼
└─────────────────────┘         Paragraph
                                ┌─────────────────────┐
                                │ code: my-sidebar    │
                                │ &lt;aside&gt;...&lt;/aside&gt;  │
                                └─────────────────────┘</code></pre></div>

<h2>Step 1: Create a paragraph with a sidebar</h2>

<p>In the CMS, create a paragraph with a unique code:</p>
<ul>
  <li><strong>name:</strong> "Sidebar PL" (internal name)</li>
  <li><strong>code:</strong> "my-sidebar-pl" (for API assignment)</li>
  <li><strong>kind:</strong> text</li>
  <li><strong>content:</strong> HTML of the sidebar</li>
</ul>

<h2>Step 2: Modify the layout</h2>

<p>Add a condition to the layout:</p>
<div style="position: relative;"><pre class="language-text" tabindex="0"><code class="language-text">{% if has_sidebar %}
&lt;section class="py-12 px-4"&gt;


      {% for p in paragraphs %}{{ p }}{% endfor %}
      &lt;main class="min-w-0 flex-1"&gt;{{ content }}&lt;/main&gt;


&lt;/section&gt;
{% else %}
&lt;main&gt;
  {% for p in paragraphs %}{{ p }}{% endfor %}
  {{ content }}
&lt;/main&gt;
{% endif %}</code></pre></div>

<p><strong>Key Liquid elements:</strong></p>
<ul>
  <li><code>{{ content }}</code> - page content (page.content)</li>
  <li><code>{% for p in paragraphs %}{{ p }}{% endfor %}</code> - assigned paragraphs</li>
  <li><code>{% if has_sidebar %}</code> - condition from page.fields.has_sidebar</li>
</ul>

<h2>Step 3a: Assignment via GUI (manually)</h2>

<p>For each page in the CMS panel:</p>
<ol>
  <li>Go to <strong>CMS → Pages</strong> and select the page to edit</li>
  <li>In the <strong>Custom Fields (fields)</strong> section, check the checkbox <code>has_sidebar</code> or add the field: <code>has_sidebar = true</code></li>
  <li>In the <strong>Paragraph Codes (paragraph_codes)</strong> field, enter the sidebar code, e.g., <code>my-sidebar-pl</code></li>
  <li>Save the page</li>
</ol>

<p><strong>Note:</strong> Make sure the paragraph with the code <code>my-sidebar-pl</code> already exists.</p>

<h2>Step 3b: Assignment via API</h2>

<p>For each page set:</p>
<div style="position: relative;"><pre class="language-css" tabindex="0"><code class="language-css">PUT /cms/pages/{id}.json?api_token=YOUR_TOKEN
{
  "page": {
    "fields": {"has_sidebar": true},
    "paragraph_codes": ["my-sidebar-pl"]
  }
}</code></pre></div>

<h2>Bulk update (bash script)</h2>

<p>When you have many pages to update at once:</p>
<div style="position: relative;"><pre class="language-css" tabindex="0"><code class="language-css">#!/bin/bash
API_TOKEN="your_token"
BASE_URL="https://yourcompany.sugester2.pl"
SIDEBAR_CODE="my-sidebar-pl"

# List of page IDs to update
PAGE_IDS=(101 102 103 104)

for PAGE_ID in "${PAGE_IDS[@]}"; do
  echo "Updating page $PAGE_ID..."
  curl -s -X PUT "$BASE_URL/cms/pages/$PAGE_ID.json?api_token=$API_TOKEN" \
    -H "Content-Type: application/json" \
    -d "{\"page\": {\"paragraph_codes\": [\"$SIDEBAR_CODE\"]}}"
  echo ""
done

echo "Done!"</code></pre></div>

<h2>Example: MyCompany</h2>

<p>Sample implementation for a feature documentation page:</p>

<table>
  <tr><th>Resource</th><th>Description</th></tr>
  <tr><td>Site</td><td>Company marketing page</td></tr>
  <tr><td>Layout</td><td>Marketing Layout with sidebar support</td></tr>
  <tr><td><strong>Sidebar PL</strong></td><td>code: <code>sidebar-funkcje-pl</code></td></tr>
  <tr><td><strong>Sidebar EN</strong></td><td>code: <code>sidebar-features-en</code></td></tr>
</table>

<p><strong>Pages to assign:</strong></p>
<ul>
  <li>Subpages in the section /funkcje/* (PL) → sidebar-funkcje-pl</li>
  <li>Subpages in the section /features/* (EN) → sidebar-features-en</li>
</ul>

<h3>Sample script</h3>
<div style="position: relative;"><pre class="language-css" tabindex="0"><code class="language-css">#!/bin/bash
API_TOKEN="your_api_token"
BASE_URL="https://yourcompany.sugester2.pl"

# PL Pages
for PAGE_ID in 101 102 103 104 105; do
  curl -s -X PUT "$BASE_URL/cms/pages/$PAGE_ID.json?api_token=$API_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"page": {"paragraph_codes": ["sidebar-funkcje-pl"]}}'
done

# EN Pages
for PAGE_ID in 201 202 203 204 205; do
  curl -s -X PUT "$BASE_URL/cms/pages/$PAGE_ID.json?api_token=$API_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"page": {"paragraph_codes": ["sidebar-features-en"]}}'
done</code></pre></div>

<p><strong>Effect:</strong> Changing the sidebar in one paragraph automatically updates all assigned pages.</p>

<h2>Debugging</h2>

<p>If the sidebar does not display:</p>
<ol>
  <li><strong>Check <code>has_sidebar</code></strong> - does the page have <code>fields.has_sidebar: true</code>?</li>
  <li><strong>Check <code>paragraph_codes</code></strong> - does it contain the correct paragraph code?</li>
  <li><strong>Check the paragraph code</strong> - does the paragraph have the <code>code</code> field set?</li>
  <li><strong>Check the layout</strong> - does it contain the loop <code>{% for p in paragraphs %}</code>?</li>
</ol>

<p>Verification via API:</p>
<div style="position: relative;"><pre class="language-bash" tabindex="0"><code class="language-bash"># Check the page
curl -s "https://yourcompany.sugester2.pl/cms/pages/ID.json?api_token=TOKEN" | jq '{paragraph_codes, fields}'

# Check paragraphs with codes
curl -s "https://yourcompany.sugester2.pl/cms/paragraphs.json?api_token=TOKEN&amp;site_id=ID" | jq '.[] | select(.code) | {id, name, code}'</code></pre></div>