smarty模板 将php数组传递给js变量
来源:互联网 发布:java基础入门电子书 编辑:程序博客网 时间:2024/05/21 06:48
php/Array ---> js /var
---config.php ---
<?php/* config data for each instance */$config = [ "instName" => "XS", 'panoAlias'=>'AXS', "lng" => 120.2, "lat" => 30.06, "planes" => array( array(120.9, 30.06, 'AXS32'), array(120.2, 30.06, 'p00') )];/*********************/if (function_exists('json_encode')) { define(CONFIG, json_encode($config));}else{ die('no json_encode function');}?>
------index.php-------
<?phprequire_once 'Smarty-3.0.8/libs/Smarty.class.php';require_once ('config.php');$smarty->assign("config",CONFIG);$smarty->display("newmap.html");?>
-----newmap.html----
<!doctype html><html> <head> <script> <span style="background-color: rgb(255, 255, 102);">var js_v = '{$config}'; <span style="color:#ff0000;">//记得引号</span></span> var config_data = eval('(' + js_v + ')'); alert(config_data['planes'][0]); </script> </head></html>
输出结果: 120.9 30.06 AXS32
另1:
smarty 模板不分析{literal}....{/literal} 之间的代码。
<!doctype html><html> <head> {literal} <script> var config= "{$config}"; alert(config); </script> {/literal} </head></html>
输出结果:{$config}
另2:
{foreach}.....{/foreach} 可用于smarty传递数组的输出。
详见:http://www.php100.com/manual/smarty/language.function.foreach.html
0 0
- smarty模板 将php数组传递给js变量
- 将php数组或者对象传递给js
- 输出php传递给模板文件的索引数组变量,关联数组变量
- 仿天猫网站开发笔记4:将Django模板变量传递给外部js调用的方案
- Smarty 模板 -- 从php分配的变量 - 数组
- js传递二维数组给php
- php数组通过smarty传值给js
- smarty模板引擎变量的传递方法
- 7、Web(js):将变量传递给下一个网页
- smarty模板中传值给php变量 从而实现不同的循环值
- 页面链接 传递js变量给php控制器
- 将php数组或者对象传递给javascript的方法
- Smarty 模板 -- 从php分配的变量
- PHP中smarty模板变量调节器
- Smarty模板php配置变量乱码问题
- php 二维数组传递给 js 问题解决记录
- 将数组传递给方法
- 将数组传递给函数
- RTP协议的H.264视频传输
- oceanbase中存储过程的实现(一)语法解析部分
- 上海联通群面
- MMC卡SPI模式
- C#版三层登录小例子
- smarty模板 将php数组传递给js变量
- appium
- Linux bash 变量
- 高低位字节序
- 追求时尚,选择西安宾利婚车租赁
- 【Cocos2d-x 3.2】裁剪节点(ClippingNode)总结
- 主机开启虚拟化支持/不能安装虚拟机解决
- C语言面试题
- 关于深度优先搜索的运用