2

So I am trying to build a dynamic Navigation bar that I am passing a certain Knowledge URL in to go to our external knowledge base. I have the Property Value on the component which I will be able to put in the URL, but the problem I have is how can I get the value to populate correctly in the Lightning Formated URL?

<lightning-formatted-url value="{knowledgeURL}" label="Knowldege"></lightning-formatted-url>

in the .js file, I do have @api and in the meta.js file, I have a target set.

@api knowledgeURL ;
<property name="knowledgeURL" type="String" default=""></property>
1
  • What you are showing now is fine I think, what is the problem you are facing? Aug 28 '19 at 16:23
3

value="{knowledgeURL}" is not correct syntax for LWC. It should be value={knowledgeURL} without ". Install the salesforce LWC extensions so that you get to know these minor errors while saving itself.

<lightning-formatted-url value={knowledgeURL} label="Knowldege"></lightning-formatted-url>

You should install Salesforce extension pack (recommended)


OLD ANSWER

If you check the documentation,

Displays a URL with a protocol such as http:// and https://. Protocol http:// is automatically prepended to a value like "my/path" to create an absolute URL. A value "/my/path" creates a relative URL.

So, you can set url without https://

Sample code:

HTML:

<template>
    <div>
        <lightning-formatted-url value={knowledgeURL} label={knowledgeLabel}></lightning-formatted-url>
    </div>
</template>

JS:

@api knowledgeURL;
@api knowledgeLabel;
9
  • 1
    I think @track should be @api according to the users use case
    – gNerb
    Aug 28 '19 at 16:27
  • 1
    @Gunner1714 added in answer - its syntax mistake. You should be using LWC extension Aug 28 '19 at 16:29
  • 1
    Also, the extension is included in the extension pack and should not be downloaded directly.
    – gNerb
    Aug 28 '19 at 16:29
  • 1
    yes, you can try and check Aug 28 '19 at 16:32
  • 1
    @gNerb thanks! added in answer for extension pack Aug 28 '19 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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