我在Silverstripe网站上找到了这个自定义js程序:
https://docs.silverstripe.org/en/3.2/developer_guides/templates/requirements/
Requirements::javascriptTemplate("cms/javascript/editor.template.js", $vars);
在需求结束时,必须如何插入$ vars,这是否可以对css文件执行相同的操作?
答案 0 :(得分:1)
请查看api docs以获取显示的信息......
if($vars) foreach($vars as $k => $v) {
$search[] = '$' . $k;
$replace[] = str_replace("\\'","'", Convert::raw2js($v));
}
$script = str_replace($search, $replace, $script);
以下数组......
$vars = array(
'iVal' => '99',
'iVal' => "'string'",
);
将转换以下JavaScript ...
var iVal = $iVal;
var sVal = $sVal;
为...
var iVal = 99;
var sVal = 'string';