concatenate JS variable in PHP

2

I have the following code and I need to be able to concatenate the variable data.id as I have it as an example in the text of the label a, since it is a second parameter that receives this route (Working with Laravel) the problem is generated by the keys, but I can not concatenate this variable

mRender: function (data, type, row) {
                        return '<a href="{{ route('user.edit', ) }}" class="btn btn-info btn-xs">hola'+data.id+'</a>'
                    }
    
asked by yeyoguzmancito 29.07.2016 в 02:03
source

2 answers

2

Right now the string is not valid (something that can be seen in the coloring of the code you share). You should escape the simple quotes that you have within other single quotes:

mRender: function (data, type, row) {
    return '<a href="' + {{ route('user.edit', 1) }} + '" class="btn btn-info btn-xs">hola'+data.id+'</a>'
}
    
answered by 29.07.2016 / 02:41
source
-1

If the code that you show us is inside some document js I think that the template system that you use will never modify it.

But in the document of the page where you load your script you could embed something like

<html>
<head>
.....
<script>var rutaUsuario = {{ route('user.edit', ) }} ;
</script><script src="miscript.js"></script>
</head>

and in the document js

mRender: function (data, type, row) {
                    return '<a href="'+rutaUsuarioID+'" class="btn btn-info btn-xs">hola'+data.id+'</a>'
                }
    
answered by 29.07.2016 в 02:46