Please excuse any syntax errors as it is not my question. I noticed some escape characters are not displaying in my href, so just know they are there in the code.
This would display the value in a link in a column template: '<a class"whatever" href="#"> #=value#',
This accounts for null values and doesn't display a link.
template: '<a class"whatever" href="#"> #=value !=null ? value: ""#',
What I am trying to achieve is to be able to use similar syntax to display a link and when the value is null it would display an error message that isn't a link.
Similar to this where it would display the value or the error.
template: ' #=value !=null ? value : "Invalid Entry"#',
This is where the problem comes in.
I cannot seem to get the syntax right to make that value a link again.
template: ' #=value !=null ? <a class"whatever" href="#"> #=value# : "Invalid Entry"#',
I've tried various combinations of wrapping it with ', ", # and nothing seems to work.
I'm trying to avoid building a separate function and calling it to determine the output, so I'm trying my best to keep this inline if I can.
Thanks.
CodePudding user response:
Please try this. I've done it here over several lines so that it is easier to read and understand but you can put it as a single line into your code (I forget if you need to escape the # in the href once or twice):
# if (value) {#
<a class"whatever" href="\\#"> #=value# </a>
#} else {#
<span>Invalid Entry</span>
#}#
The # marker is used to switch between javascript and outputting html (any # within html needs to be escaped). It is also used to mark data values to be output. Those can be rendered either as html, for example:
#:value#
or with html encoding:
#=value#
You can't put javascript code in those which is why you are struggling with your template.