给出液体模板机车类
我有以下液体标记:
{{ 'image.jpg' | theme_image_tag }}
它呈现为,
<img src="/site.com/site/3424242/image.jpg" />
如何向其添加类或任何选项?我希望它的渲染效果如下:
<img src="/site.com/site/3424242/image.jpg" class="thumbnail" />
我使用 Locomotive CMS 及其附带的液体。
I have the following liquid markup:
{{ 'image.jpg' | theme_image_tag }}
and it renders like,
<img src="/site.com/site/3424242/image.jpg" />
How to add a class or whatever option to it? I want it to render like:
<img src="/site.com/site/3424242/image.jpg" class="thumbnail" />
I use the Locomotive CMS and the liquid that comes with it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
对于大多数控制,请考虑使用
theme_image_url
而不是theme_image_tag
。这是一个更详细的示例,应该可以满足您的需求。For the most control, consider using
theme_image_url
instead oftheme_image_tag
. Here's a more detailed example that should get you want you want.<img src="{{ 'image.jpg' | theme_image_url }}" class="thumbnail" />
尽管文档没有明确说明这一点,但您可以将类添加到
image_tag
或theme_image_tag
过滤器如下所示:更一般地说,您可以添加任意 HTML 属性。像这样的流式代码...
将生成如下 HTML:
Although the docs don't make this clear, you can add classes to the
image_tag
ortheme_image_tag
filters like this:More generally, you can add arbitrary HTML attributes. Liquid code like this...
will produce HTML like this:
如果您想自定义液体,可以考虑编辑位于 lib/locomotive/liquid/filters/html.rb 中的 html.rb 文件。
或者您甚至可以编辑当前的 theme_image_tag 过滤器。
If you want to customize your liquid, you could consider editing the html.rb file located in lib/locomotive/liquid/filters/html.rb .
Or you can even edit the current theme_image_tag filter.
image_tag 和 theme_image_tag 之间的区别在于 image_tag 将为您提供后端上传的数据中的 url,而 theme_image_tag 是您从主题中获得的 URL。
两者都接受参数。
干杯,
霍里昂·格雷戈里
the difference between image_tag and theme_image_tag is taht image_tag will give you the url from the data you have upload in your backend and theme_image_tag is the one you get form your theme.
both accept params.
cheers,
Horion grégory
输出过滤器从左到右运行,因此您也可以这样做:
Locomotive CMS 可能有自己的过滤器,但有关的代码应该通用。
Output filters run from left to right, so you could also do this:
Locomotive CMS may have its own filters, but the code about should work universally.
对我来说,以下工作有效
For me, the following worked