> For the complete documentation index, see [llms.txt](https://docs.realmacsoftware.com/elements-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.realmacsoftware.com/elements-docs/elements-language/component/hooks.js/passing-data-to-templates.md).

# Passing data to templates

To send data to your templates, you can utilise the `rw.setProps()` method. By passing an object to this method, you are able to dynamically inject data into your templates.

#### Example 1: Simple Property Passing

```javascript
const transformHook = (rw) => {
  const message = 'Hello, World!';

  rw.setProps({
    greetingMessage: message
  });
};

exports.transformHook = transformHook;
```

#### Example 2: Conditional Logic for Display

```javascript
const transformHook = (rw) => {
  const { isVisible } = rw.props;

  const display = isVisible ? 'visible' : 'hidden';

  rw.setProps({
    display
  });
};

exports.transformHook = transformHook;
```

#### Example 3: Basic Computation and Formatting

```javascript
const transformHook = (rw) => {
  const { quantity } = rw.props;

  const totalPrice = quantity * 15; // Assuming price per item is 15
  const formattedPrice = `$${totalPrice.toFixed(2)}`;

  rw.setProps({
    formattedPrice
  });
};

exports.transformHook = transformHook;
```

#### Example 4: String Manipulation

```javascript
const transformHook = (rw) => {
  const { username } = rw.props;

  const welcomeMessage = `Welcome, ${username.charAt(0).toUpperCase() + username.slice(1)}!`;

  rw.setProps({
    welcomeMessage
  });
};

exports.transformHook = transformHook;
```

#### Example 5: Complex Calculation using collection data

```javascript
const transformHook = (rw) => {
  const { items } = rw.collections;

  const totalWeight = items.reduce((accumulator, item) => accumulator + item.weight, 0);

  const shippingCost = totalWeight > 10 ? totalWeight * 1.5 : totalWeight * 1.2;

  const formattedShippingCost = `$${shippingCost.toFixed(2)}`;

  rw.setProps({
    totalWeight,
    formattedShippingCost
  });
};

exports.transformHook = transformHook;.
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.realmacsoftware.com/elements-docs/elements-language/component/hooks.js/passing-data-to-templates.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
