0

I have this code in PHP and I cannot get item.thumb to work. Its something with quotes, I have tried everything. It stays as a string. item.id, item.title, item.description work fine.

This line is the problem:

"<img class=\"hap-selectize-thumb\" src=\" + item.thumb + \" />" +

Here is the whole:

$markup .= '<script type="text/javascript">
            jQuery(document).ready(function() {
                jQuery(".'.$id.'").selectize({
                    searchField: ["title","description"],
                    valueField: "id",
                    labelField: "title",
                    placeholder: "'.$placeholder.'",   
                    options: '.json_encode($data).',
                    render: {
                        option: function (item, escape) {

                        return "<div class=\"hap-selectize-option\">" +
                                "<div class=\"hap-selectize-image\">" +
                                       "<img class=\"hap-selectize-thumb\" src=\" + item.thumb + \" />" +
                               "</div>" +
                                "<div class=\"hap-selectize-text\">" +
                                    "<span class=\"hap-selectize-value\">" + item.id + "</span>" +
                                    "<span class=\"hap-selectize-title\">" + escape(item.title) + "</span>" +
                                    "<p class=\"hap-selectize-description\">" + escape(item.description) + "</p>" +
                               "</div>" +
                            "</div>";
                        }
                    },
                });
            });
            </script>'; 
Toniq
  • 4,492
  • 12
  • 50
  • 109
  • Try also here : https://stackoverflow.com/questions/25344349/php-variable-with-quotes-in-javascript – Martin Jul 23 '21 at 11:00
  • You need to double wrap with the JS quotes as well as the PHP quotes, so: `... src=\" " + item.thumb + " \" ...` – Martin Jul 23 '21 at 11:01
  • 1
    Wouldn't a HEREDOC solve half your issues? (And a second one the other half.) – mario Jul 23 '21 at 11:09

0 Answers0