我正在使用aBigImage Jquery,当我按照给出的指示时,我得到一个500错误,说变量" link"不存在。 你能帮我么? 以下代码是我写的:
{% block body %}
<div class="page-sidebar">
{% for link in entity.getSidebarImages() %}
{% if link.image.isFoto() %}
<a href="{{ app.request.basepath }}/{{ link.image.getWebPath() }}">
<img src="{{ app.request.basepath }}/{{ link.image.getWebPath("thumbnail_250") }}" alt="{{ link.image.title }}">
<div class="sidebar-description">
{{ link.image.description|raw }}
</div>
</a>
{% else %}
<div class="sidebar-item sidebar-link-item">
<a href="{{ app.request.basepath }}/{{ link.image.webpath }}">
<img src="{{ app.request.basepath }}/{{ link.image.getPreview() }}" />
</a>
<div class="sidebar-title">
<a href="{{ app.request.basepath }}/{{ link.image.webpath }}">
{{ link.image.title|raw }}
</a>
</div>
</div>
{% endif %}
{% endfor %}
<script>
jQuery('.page-sidebar a').on('click') {
jQuery(document).ready(function(
$( 'a[href$="'{{ app.request.basepath }}'/'{{ link.image.getWebPath() }}'"]').abigimage();
});
</script>
</div>
{% endblock %}
{% block body_javascripts %}
{% javascripts output='aBigImage.js'
'@CtrlBlnHomepageBundle/Resources/public/js/Minimal-jQuery-Image-Viewer-with-Image-Preloading-ABigImage/abigimage.jquery.min.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
我得到的错误是:
$( 'a[href$="'{{ app.request.basepath }}'/'{{ link.image.getWebPath() }}'"]').abigimage();
我觉得这是一个语法错误,但我找不到它......谢谢!
答案 0 :(得分:0)
您正在 循环之外引用 link 变量。
答案 1 :(得分:0)
不确定为什么要创建辅助选择器,将其切换到应该可以正常工作
$(function() {
$('.page-sidebar a').abigimage();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://www.darkbee.be/abigimage.jquery.min.js"></script>
<div class="page-sidebar">
{% for link in entity.getSidebarImages() %}
{% if link.image.isFoto() %}
<a href="{{ app.request.basepath }}/{{ link.image.getWebPath() }}">
<img src="{{ app.request.basepath }}/{{ link.image.getWebPath("thumbnail_250") }}" alt="{{ link.image.title }}">
<div class="sidebar-description">{{ link.image.description|raw }}</div>
</a>
{% else %}
<div class="sidebar-item sidebar-link-item">
<a href="{{ app.request.basepath }}/{{ link.image.webpath }}">
<img src="{{ app.request.basepath }}/{{ link.image.getPreview() }}" />
</a>
<div class="sidebar-title">
<a href="{{ app.request.basepath }}/{{ link.image.webpath }}">
{{ link.image.title|raw }}
</a>
</div>
</div>
{% endif %}
{% endfor %}
</div>