简体   繁体   English

将变量从php传递到html / js

[英]pass variable from php to html / js

So I have a JavaScript that returns an output variable looking like this: 因此,我有一个JavaScript可以返回如下所示的输出变量:

<script id="cat-template" type="text/x-handlebars-template">
    <div class="chart">
        <h2>{{Name}}</h2>
        <h3 style="color:#ff0099;font-size:250%"> {{Status}}</h3>

</script>

What I would like to do is have it as a part of this php snippet: 我想做的是将其作为此php代码段的一部分:

<?php
    $status = {{Status}};
    if ($status = "1") {
        echo "Good day, bud!";}
    else {
        echo "Good night, pal!";}
?>

the {{Status}} doesn't work in the php snippet. {{Status}}在php代码段中无效。

Any thoughts? 有什么想法吗?

You Must On Parse HTML AND JavaScript AS PHP String 您必须解析HTML和JavaScript作为PHP字符串

Simple Example : 简单的例子:

index.html index.html

<html>
<head>
....
....
....
</head>
<body>
<p>Your Username Is :{{username}}</p>
</body>
</html>

PHP Code : PHP代码:

<?php 
$username ="Test";
$content=file_get_contents("/theme/index.html");
$content=str_replace("{{username}}",$username,$content);

echo $content;

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM