> ## Documentation Index
> Fetch the complete documentation index at: https://learn.nextedy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Scope a Server-Rendered Column to a Collection

> Make a Nextedy POWERSHEET server-rendered property show only data from the Polarion Collection the sheet is opened in, by reading the Collection id from the sheet URL inside the Velocity template.

export const LastReviewed = ({date, state}) => {
  if (!date) return null;
  const formatted = new Date(`${date}T00:00:00Z`).toLocaleDateString("en-US", {
    year: "numeric",
    month: "long",
    day: "numeric",
    timeZone: "UTC"
  });
  const label = state === "reviewed" ? `Last reviewed and confirmed up to date on ${formatted}` : `Last updated on ${formatted}`;
  return <p className="mt-10 text-sm text-gray-400 dark:text-zinc-500 not-prose">
      {label}
    </p>;
};

A sheet opened inside a Polarion Collection narrows its rows, expanded levels and pickers to that Collection. A `serverRender` template is different: whatever it searches for or reads on its own stays project-wide until the template itself asks which Collection the sheet is in. This guide shows how to do that, using a column that lists a work item's linked items as the example.

## Prerequisites

* A data model with a [server-rendered property](/powersheet/guides/server-rendering/create-computed-property)
* A sheet that you open inside a Collection with the `_collection` URL parameter (see [Open a Sheet in a Polarion Collection](/powersheet/guides/queries/open-a-sheet-in-a-polarion-collection))

<Steps>
  <Step title="Read the Collection Id">
    The template sees the sheet's URL parameters in `$context.parameters`. Read the Collection id with `.get("_collection")`:

    ```velocity theme={null}
    #set($colId = "")
    #set($colId = $context.parameters.get("_collection"))
    ```

    Outside a Collection the parameter is absent, and `$colId` keeps the empty string from the first line.

    <Warning>
      **Use `.get("_collection")`, not the dot form**

      `$context.parameters._collection` does not work. A Velocity name cannot start with an underscore, so the cell shows the reference as literal text instead of the id. The same holds for every URL parameter whose name starts with `_`.
    </Warning>
  </Step>

  <Step title="Branch on It">
    Keep the template's existing behavior for a sheet opened without a Collection, and add a branch for a sheet opened inside one:

    ```velocity theme={null}
    #if($colId && $colId != "")
      ## …inside a Collection: read only what belongs to it…
    #else
      ## …no Collection: what the template rendered before…
    #end
    ```
  </Step>

  <Step title="Resolve the Collection and Narrow the Read">
    Inside the Collection branch, resolve the Collection from its id, then use it to decide what the template shows. This example lists the ids of the work items linked from the row. Inside a Collection it keeps only those whose document belongs to the Collection:

    ```velocity theme={null}
    #set($colId = "")
    #set($colId = $context.parameters.get("_collection"))
    #set($col = false)
    #if($colId && $colId != "")
      #set($col = $trackerService.getBaselineCollectionsManager().getCollection($context.getProjectId(), $colId))
    #end
    #foreach($linked in $wi.getLinkedWorkItems())
      #if(!$col || ($linked.getModule() && $col.getElement($linked.getModule())))
        $linked.getId()
      #end
    #end
    ```

    `$col.getElement(…)` returns the Collection's entry for a document, and nothing when the document is not in the Collection. A linked item that lives in no document, or in a document outside the Collection, is therefore left out. Without a Collection, `$col` stays `false` and every linked item is listed, as before.

    `$trackerService` is one of the [Polarion services](/powersheet/guides/server-rendering/access-polarion-services) available to every template, and `$wi` is the row's work item.
  </Step>
</Steps>

## Verify

1. Open the sheet without `_collection`. The column shows what it showed before.
2. Open the same sheet with `_collection=<id>`. The column shows only data from that Collection: in the example, only linked items whose document the Collection contains.
3. Open it with the id of a second Collection that contains different documents. The column changes with the Collection.

## What to Keep in Mind

* **Scoping is opt-in per template.** A server-rendered property that does not read the Collection id keeps showing project-wide results inside a Collection. Review each such property before relying on it in a collection-scoped sheet.
* **The id comes from the sheet URL.** The template sees a Collection only when the sheet was opened with `_collection`.
* **The rows are already scoped.** The sheet only renders rows the Collection contains. Only what the template fetches on its own needs the steps above.
* **Templates stay read-only.** Reading the Collection does not let a template change Polarion data.

## See Also

* [Collection-Scoped Sheets](/powersheet/concepts/collection-scoped-sheets) — what a Collection changes in each part of a sheet
* [Context Variables](/powersheet/reference/server-rendering/context-variables) — `$context.parameters` and the other variables a template receives
* [Access Polarion Services](/powersheet/guides/server-rendering/access-polarion-services) — `$trackerService` and the other platform services
* [Debug Template Errors](/powersheet/guides/server-rendering/debug-template-errors) — what to check when a cell shows `#SERVER_RENDER_ERROR`

<LastReviewed date="2026-10-05" />


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.