# processContent in Aurelia 2

**URL:** <https://discourse.aurelia.io/t/processcontent-in-aurelia-2/5180>\
**Category:** vNext\
**Created:** [June 7, 2023, 3:20pm UTC](https://discourse.aurelia.io/t/processcontent-in-aurelia-2/5180 "2023-06-07T15:20:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elitastic](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/elitastic/32/1787_2.png) [@elitastic](https://discourse.aurelia.io/u/elitastic)\
**Post date:** [June 7, 2023, 3:20pm UTC](https://discourse.aurelia.io/t/processcontent-in-aurelia-2/5180/1 "2023-06-07T15:20:12Z")

</div>

In Aurelia 1 there was the `@processContent` decorator, is there something similar in Aurelia 2?

I found the following, but `processContent` is not called. Could someone help me?

> **[process-content - StackBlitz](https://stackblitz.com/edit/au2-conventions-iorkaj)**
>
> Run Aurelia application with conventions

```auto
import { IPlatform, customElement, INode } from 'aurelia';

@customElement({
  name: 'products',
  template: '<span>id: ${id}</span>',
  processContent: (node: INode, platform: IPlatform) => {
    alert('test');
    console.log(node);
  },
})
export class Products {
  id = 100;
}

```

---

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [June 7, 2023, 5:39pm UTC](https://discourse.aurelia.io/t/processcontent-in-aurelia-2/5180/2 "2023-06-07T17:39:09Z")

</div>

Hi @elitastic! It does work. Here is an example: [process-content (forked) - StackBlitz](https://stackblitz.com/edit/au2-conventions-wng8w3?file=src%2Ffoo-bar.ts,src%2Fproducts.ts,src%2Fproducts.html)

Note that `processContent` is a hook that is invoked during template compilation statically. That is when the CE (ce1) that has the `processContent` hook, is used statically in the template of another CE (ce2), during the template compilation of ce2, the `ce2#processContent` will be invoked. However, for router, we are dynamically adding and removing component to and from the viewport. Invoking `processContent` on such cases makes little sense, considering the use-case, `processContent` intend to solve in the first place.

---

<div class="post-metadata">

**Author:** ![elitastic](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/elitastic/32/1787_2.png) [@elitastic](https://discourse.aurelia.io/u/elitastic)\
**Post date:** [June 9, 2023, 6:40am UTC](https://discourse.aurelia.io/t/processcontent-in-aurelia-2/5180/3 "2023-06-09T06:40:41Z")

</div>

Hi @Sayan751, thanks for your help. I was just playing around on StackBlitz with Au2, my use case was not well chosen. Sorry for that.

I took your example and modified it like:

```auto
import { INode, IPlatform } from '@aurelia/runtime-html';

export class FooBar {
  value = 'hooray';

  static processContent(node: INode, platform: IPlatform) {
    var span = document.createElement('span');

    span.innerHTML = '<span>${value}red</span>';

    node.appendChild(span);

    return true;
  }
}

```

> **[process-content v2 - StackBlitz](https://stackblitz.com/edit/au2-conventions-yj3ych?file=src%2Ffoo-bar.ts)**
>
> Run Aurelia application with conventions

Should this work or did I misunderstand “processContent”?

---

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [June 11, 2023, 4:03pm UTC](https://discourse.aurelia.io/t/processcontent-in-aurelia-2/5180/4 "2023-06-11T16:03:46Z")

</div>

Actually, you want to use the `processContent` hook to adjust the declarative template passed from the usage side, to something more native to Aurelia. For example, when you are designing a tabs control, one way to do this can be to have 2 separate bindables for the tab header and content. Then you can do the following.

```html
<tabs headers.bind content.bind></tabs>

```

But that would not offer any semantics. Rather than doing that, you can allow the following templating syntax.

```html
  <tabs>
    <tab header="Tab1">
      <span>content 1</span>
    </tab>
    <tab header="Tab2">
      <span>content 2</span>
    </tab>
    <tab header="Tab3"> Nothing to see here. </tab>
</tabs>

```

With that, you offer more semantics for the user of the control. And in the background, you use the `processContent` hook to convert that template to something more manageable for Aurelia.

Here is an example of this: [process-content v2 (forked) - StackBlitz](https://stackblitz.com/edit/au2-conventions-qtwdqh?file=src%2Ftabs.ts,src%2Fproducts.ts)

It seemed to me that you have tried to override the template of the foo-bar CE from the `processContent` hook. That is not a thing, for which you should use the `processContent` hook. Note also that when you are adding new children HTML nodes under the foo-bar node, these template changes happen in the context where the foo-bar CE is used. Thus, in your case, you are technically expecting a `value` property in the CE, that is using the foo-bar CE. Although this kind of expectation indicates not-sound designs, here is a modified version of your example, when we still pursue this: [process-content v2 (forked) - StackBlitz](https://stackblitz.com/edit/au2-conventions-xzcrrk?file=src%2Ffoo-bar.ts,src%2Ffoo-bar.html,src%2Fproducts.ts)

Note that the foo-bar CE now uses a slot.

Hope this explanation helps.
