laravel blade @yield inside js

时间:2012-12-18 04:06:42

标签: laravel matomo blade

您好我正在尝试使用刀片为我的网站创建动态跟踪代码。 这是我到目前为止我尝试直接屈服于piwikTracker var,但得到各种错误传递它作为一个var似乎工作但我现在没有得到任何统计数据在后端

 <!-- Piwik --> 
<script type="text/javascript">
var track =  @yield('track');
var pkBaseURL = (("https:" == document.location.protocol) ? "https://centralcoastwindowcleaners.com.au/track/" : "http://centralcoastwindowcleaners.com.au/track/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", track);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://centralcoastwindowcleaners.com.au/track/piwik.php?         idsite=@yield('track')" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->

有没有办法可以逃脱它并做类似的事情:

<!-- Piwik --> 
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://centralcoastwindowcleaners.com.au/track/" : "http://centralcoastwindowcleaners.com.au/track/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", @yield('track'));
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://centralcoastwindowcleaners.com.au/track/piwik.php?         idsite=@yield('track')" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->

1 个答案:

答案 0 :(得分:0)

在您显示的上下文中,您不需要生成节,只需要变量或字符串。这样你就可以通过这个只是

var track =  {{$track}};

剖面对于嵌套视图和部分视图很有帮助,但对于单个变量来说是过度杀伤(以及未设计)。如果由于某种原因你不能存储和传递$ track,那么用yield而不是变量传递整行。

//var track = 'varYouArePassing';
@yield('track');