1

This question already has an answer here:

I have the following code and I need to insert a '/' in my href property.

<template for:each={assetData} for:item="item" for:index="indexvar">
   <tr class="slds-hint-parent" key={item.Id}>
      <td>
         {item.Name}
      </td>
      <td>
         <a href={item.Id} target="_blank">{item.Account.Name}</a>
      </td>
   </tr>
</template>

On aura component, I can easily do something like

<a href="{!'/' + item.Id}" target="_blank">{!item.Account.Name}</a>

But lwc does not allow me to do the same.

marked as duplicate by Pranay Jaiswal, Vijay Ganji, Community Jul 4 at 12:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

LWCs Templates are logicless and don`t support any Expressions anymore (see also here/here)

The engine doesn’t allow computed expressions

In your case you should either add a new computed property to your items in your assetData at runtime or create a child component (passing the id) which internally uses a getter or tracked variable which builds the link

Not the answer you're looking for? Browse other questions tagged or ask your own question.