-2

I currently use this html code {{ou.user_agent}}

Which results in the build which results in the user agent.

To identify an exact word I do this {{ou.user_agent == "Store" ? "Go" : "Nope"}}

If the user agent contains Store exactly, it returns Go and if it does not, it returns Nop.

The problem with this is that it requires exactly the word.

What I need is that of "Go" if "Store" is inside the string.

What I need would be something like this in PHP but in HTML Example code:

if(strpos($useragent, "Store") !== false){
//Note this is a demo code of what I want to achieve but in HTML
}

The detail is that it is in HTML and I don't know how to do it.

I am editing a template extension ".tpl.php" of Live Helper Chat

The code is outside the PHP tags as if it were HTML.

Edu Rafael
  • 51
  • 5
  • 1
    Does this answer your question? [How to check whether a string contains a substring in JavaScript?](https://stackoverflow.com/questions/1789945/how-to-check-whether-a-string-contains-a-substring-in-javascript) – Ivar Aug 25 '22 at 06:54
  • `ou.user_agent == "Store" ? "Go" : "Nope"` most certainly is JavaScript. HTML doesn't have this out of the box so you must be using some templating framework/library. You haven't shown which one, but it almost certainly uses JavaScript. (Also note that the highest scored answer there is exactly the answer of Gelu below, which you confirmed that works.) – Ivar Aug 25 '22 at 07:01
  • Hello, I'm sorry, so I didn't know what language it was since it was outside the php fields as if it were html – Edu Rafael Aug 25 '22 at 07:09

1 Answers1

0

Try {{ou.user_agent.includes("Store") ? "Go" : "Nope"}}

Gelu Ungur
  • 69
  • 5
  • Please don't answer questions that have been asked many times before on Stack Overflow. Instead, flag them to be closed as a [duplicate](https://stackoverflow.com/help/duplicates). See [answer]. – Ivar Aug 25 '22 at 06:55
  • It works thank you very much! However, I find myself in doubt as to what language is this? Is it HTML? because it is outside the PHP tags and has double brackets? – Edu Rafael Aug 25 '22 at 06:58
  • It's Javascript. You can't write complex logic in raw HTML. – Gelu Ungur Aug 25 '22 at 06:59
  • 1
    @Ivar thanks for the heads-up, but I didn't have enough reputation points to flag posts. I do now :) – Gelu Ungur Aug 25 '22 at 07:00
  • So to format it, do double brackets work? – Edu Rafael Aug 25 '22 at 07:00