> 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/available-data/rw.element.md).

# rw\.component

The `rw.component` object provides metadata about the component itself, including paths to assets.

## Properties

| Property          | Type    | Description                                                                                                                                          |
| ----------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `title`           | String  | The component's name                                                                                                                                 |
| `group`           | String  | The component group/category                                                                                                                         |
| `version`         | Integer | Component version number (not the Elements app — see [`rw.system`](/elements-docs/elements-language/component/hooks.js/available-data/rw.system.md)) |
| `build`           | Integer | Component build number (not the Elements app — see [`rw.system`](/elements-docs/elements-language/component/hooks.js/available-data/rw.system.md))   |
| `assetPath`       | String  | Path to component-specific assets                                                                                                                    |
| `siteAssetPath`   | String  | Path to site-level component assets                                                                                                                  |
| `sharedAssetPath` | String  | Path to shared pack assets                                                                                                                           |

## Accessing Component Data

```javascript
const transformHook = (rw) => {
    const {
        title,
        assetPath,
        sharedAssetPath
    } = rw.component;

    console.log(title);           // "Image Gallery"
    console.log(assetPath);       // "/resources/components/gallery/"
    console.log(sharedAssetPath); // "/resources/shared/"
};

exports.transformHook = transformHook;
```

## Using Asset Paths

Asset paths are essential for referencing component resources like images, scripts, and stylesheets:

```javascript
const transformHook = (rw) => {
    const { assetPath, sharedAssetPath } = rw.component;

    rw.setProps({
        // Component-specific assets
        placeholderImage: `${assetPath}/images/placeholder.png`,
        componentScript: `${assetPath}/js/gallery.js`,

        // Shared assets across the pack
        sharedIcon: `${sharedAssetPath}/icons/arrow.svg`,
        sharedStyles: `${sharedAssetPath}/css/common.css`
    });
};

exports.transformHook = transformHook;
```

## Placeholder Images in Edit Mode

A common pattern is showing placeholder images while editing:

```javascript
const transformHook = (rw) => {
    const { mode } = rw.project;
    const { sharedAssetPath } = rw.component;
    const { image } = rw.props;

    const isEditMode = mode === 'edit';
    const hasImage = image && image.image;

    // Show placeholder in edit mode when no image is set
    const displayImage = hasImage
        ? image.image
        : (isEditMode ? `${sharedAssetPath}/images/placeholder.png` : null);

    rw.setProps({
        displayImage,
        hasImage
    });
};

exports.transformHook = transformHook;
```

## Using in Templates

```html
<!-- Component-specific assets -->
<img src="{{assetPath}}/images/icon.png" alt="Icon">

<!-- Shared pack assets -->
<link rel="stylesheet" href="{{sharedAssetPath}}/css/styles.css">

<!-- Conditionally load scripts -->
@if(needsGalleryScript)
    <script src="{{assetPath}}/js/gallery.min.js"></script>
@endif
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.realmacsoftware.com/elements-docs/elements-language/component/hooks.js/available-data/rw.element.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
