着色器 树枝生长_您应该知道的10个树枝过滤器

着色器 树枝生长

If you’ve ever used Twig before you probably already know about filters and chances are you use them quite often. Filters are very powerful and allow you to modify a variable in an easy yet elegant way. There are lots of filters available and it’s possible that you don’t know all of them yet.

如果您曾经使用过Twig,可能已经对过滤器有所了解,那么您很有可能会经常使用它们。 过滤器非常强大,可让您以简单而优雅的方式修改变量。 有很多可用的过滤器,可能您还不了解所有过滤器。

That’s exactly why we’ll go over this list of filters in this article. But before we continue, I want you to know that you can play around with these filters on twigfiddle.com. This website provides a small online playground where you can fiddle around with Twig. This saves you the hassle of setting up an environment on your local machine.

这就是为什么我们将在本文中介绍此过滤器列表的原因。 但是,在继续之前,我希望您知道可以在twigfiddle.com上使用这些过滤器。 该网站提供了一个小的在线游乐场,您可以在其中闲逛Twig。 这省去了在本地计算机上设置环境的麻烦。

Without further ado, let’s jump straight into the 10 Twig filters you should know.

事不宜迟,让我们直接进入您应该知道的10个Twig过滤器。

1.默认 (1. default)

The default filter returns a specified default value that will be returned if the value is undefined or empty, otherwise the value of the variable gets returned. This filter works on variables but also on objects and arrays.

默认过滤器返回指定的默认值,如果该值未定义或为空,则将返回该默认值,否则将返回该变量的值。 该过滤器不仅适用于变量,而且适用于对象和数组。

{{ name|default('No name defined') }}
{{ person.age|default('Age is not defined') }}
{{ person['age']|default('Age is not defined') }}

2. nl2br (2. nl2br)

nl2br stands for new line to br which means that this filter inserts HTML line breaks before all newlines in a string. All new lines (\n) get replaced by an HTML <br> tag.

nl2br代表br的换行符,这意味着该过滤器在字符串中的所有换行符之前插入HTML换行符。 所有新行( \n )都将替换为HTML <br>标记。

{{ "Hey, how are you?\nJust fine."|nl2br }}{# outputs    Hey, how are you?<br />    Just fine.#}

3.未加工 (3. raw)

By default, everything in Twig gets escaped when automatic escaping is enabled. If you don’t want to escape a variable you’ll have to explicitly mark it as safe which you can do by using the raw filter. This only works if the raw filter is the last filter that is applied to the filter.

默认情况下,启用自动转义后,Twig中的所有内容都会转义。 如果您不想转义变量,则必须将其显式标记为安全,这可以通过使用原始过滤器来实现。 仅当原始过滤器是应用于该过滤器的最后一个过滤器时,此方法才有效。

This filter can be useful when you want to render a variable that contains HTML, for example. In that case, you don’t want to escape the variable but rather render it as is.

例如,当您要呈现一个包含HTML的变量时,此过滤器会很有用。 在这种情况下,您不想转义变量,而是按原样呈现它。

{{ data|raw }} {# The data variable won't be escaped #}

4.日期 (4. date)

The date filter formats a date variable to a given format. You can pass in the desired format as the first parameter. The second parameter is optional and gets used to specify the timezone.

日期过滤器将日期变量格式化为给定格式。 您可以将所需的格式作为第一个参数传递。 第二个参数是可选的,用于指定时区。

{{ updated_at|date("d/m/Y") }}
{{ "now"|date("d/m/Y") }}
{{ updated_at|date("d/m/Y", "Europe/Amsterdam") }}

5.批处理 (5. batch)

The batch filter splits up a list in a list of lists — each sublist being called a batch. The first argument specifies the size of a batch. The second argument is a placeholder that gets used to fill in missing items.

批处理过滤器在列表列表中拆分一个列表-每个子列表都称为batch 。 第一个参数指定批处理的大小。 第二个参数是一个占位符,用于填充缺少的项目。

{% set names = ['John', 'Lisa', 'Frank', 'Ted'] %}
<table>
{% for row in names|batch(3, 'No name') %}
<tr>
{% for column in row %}
<td>{{ column }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>

This is what it will look like once it gets rendered:

呈现后的外观如下所示:

<table>
<tr>
<td>John</td>
<td>Lisa</td>
<td>Frank</td>
</tr>
<tr>
<td>Ted</td>
<td>No name</td>
<td>No name</td>
</tr>
</table>

6.更换 (6. replace)

The replace filter formats a given string by replacing the placeholders. The replace filter has one parameter which is an object. The key specifies what needs to be replaced and the corresponding value specifies what it needs to be replaced with.

替换过滤器通过替换占位符来格式化给定的字符串。 替换过滤器具有一个作为对象的参数。 键指定需要替换的内容,相应的值指定需要替换的内容。

Note that using % as a delimiter purely conventional and thus optional.

请注意,使用作为分隔符纯粹是常规的,因此是可选的。

{{ "This is %name% and my hobby is %hobby%."|replace({'%name%': "Fred", '%hobby%': hobby}) }}{# This is Fred and my hobby is tennis. #}{{ "I have a dog"|replace({'dog': 'cat'}) }}{# I have a cat #}

7.首先 (7. first)

The first filter returns the first element of a sequence, a mapping, or a string.

一个过滤器返回序列,映射或字符串的第一个元素。

{{ ['a', 'b', 'c', 'd']|first }}{# outputs a #}
{{ { a: 1, b: 2, c: 3, d: 4 }|first }}{# outputs 1 #}
{{ 'abcd'|first }}{# outputs a #}

Just like there is the first filter there’s also the last filter.

就像第一个过滤器一样, 最后一个过滤器也一样。

{{ ['a', 'b', 'c', 'd']|last }}{# outputs d #}
{{ { a: 1, b: 2, c: 3, d: 4 }|last}}{# outputs 4 #}
{{ 'abcd'|last}}{# outputs d #}

8.无空间 (8. spaceless)

The spaceless filter removes whitespace between HTML tags. Note that it doesn’t remove whitespace within HTML tags.

无空间过滤器可删除HTML标签之间的空白。 请注意,它不会删除HTML标记内的空格。

This tag is meant to avoid extra whitespace between HTML tags to avoid browser rendering quirks under some circumstances. It isn’t meant to keep the size of the generated HTML to a minimum.

此标记旨在避免HTML标记之间出现多余的空格,以免在某些情况下浏览器呈现怪异。 这并不意味着将生成HTML的大小保持最小。

"<div>
<label>Some text</label>
</div>
"|spaceless }}{# output will be <div><label>Some text</label></div> #}

9.圆 (9. round)

The round filter rounds a number to a given precision. The first parameter is the precision, with a default value of 0. The second parameter is the rounding method which defaults to common. Other possible rounding methods are ceil and floor.

舍入过滤器将数字舍入到给定的精度。 第一个参数是精度,默认值为0。第二个参数是默认为common的舍入方法。 其他可能的舍入方法是ceilfloor

{{ 14.65|round }}{# outputs 15#}
{{ 14.65|round(1, 'floor') }}{# outputs 14.6 #}{{ 14.65|round(1, 'ceil') }}{# outputs 14.7 #}

10.按键 (10. keys)

The keys filter returns the keys of an array which comes in handy when you want to iterate over the keys of an array.

keys过滤器返回数组的键,当您要遍历数组的键时,派上用场。

{% for key in items|keys %}
...
{% endfor %}

翻译自: https://levelup.gitconnected.com/10-twig-filters-you-should-know-9719285d1f83

着色器 树枝生长

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
自动控制节水灌溉技术的高低代表着农业现代化的发展状况,灌溉系统自动化水平较低是制约我国高效农业发展的主要原因。本文就此问题研究了单片机控制的滴灌节水灌溉系统,该系统可对不同土壤的湿度进行监控,并按照作物对土壤湿度的要求进行适时、适量灌水,其核心是单片机和PC机构成的控制部分,主要对土壤湿度与灌水量之间的关系、灌溉控制技术及设备系统的硬件、软件编程各个部分进行了深入的研究。 单片机控制部分采用上下位机的形式。下位机硬件部分选用AT89C51单片机为核心,主要由土壤湿度传感器,信号处理电路,显示电路,输出控制电路,故障报警电路等组成,软件选用汇编语言编程。上位机选用586型以上PC机,通过MAX232芯片实现同下位机的电平转换功能,上下位机之间通过串行通信方式进行数据的双向传输,软件选用VB高级编程语言以建立友好的人机界面。系统主要具有以下功能:可在PC机提供的人机对话界面上设置作物要求的土壤湿度相关参数;单片机可将土壤湿度传感器检测到的土壤湿度模拟量转换成数字量,显示于LED显示器上,同时单片机可采用串行通信方式将此湿度值传输到PC机上;PC机通过其内设程序计算出所需的灌水量和灌水时间,且显示于界面上,并将有关的灌水信息反馈给单片机,若需灌水,则单片机系统启动鸣音报警,发出灌水信号,并经放大驱动设备,开启电磁阀进行倒计时定时灌水,若不需灌水,即PC机上显示的灌水量和灌水时间均为0,系统不进行灌水。
智慧农业是一种结合了现代信息技术,包括物联网、大数据、云计算等,对农业生产过程进行智能化管理和监控的新模式。它通过各种传感器和设备采集农业生产中的关键数据,如大气、土壤和水质参数,以及生物生长状态等,实现远程诊断和精准调控。智慧农业的核心价值在于提高农业生产效率,保障食品安全,实现资源的可持续利用,并为农业产业的转型升级提供支持。 智慧农业的实现依赖于多个子系统,包括但不限于设施蔬菜精细化种植管理系统、农业技术资料库、数据采集系统、防伪防串货系统、食品安全与质量追溯系统、应急追溯系统、灾情疫情防控系统、农业工作管理系统、远程诊断系统、监控中心、环境监测系统、智能环境控制系统等。这些系统共同构成了一个综合的信息管理和服务平台,使得农业生产者能够基于数据做出更加科学的决策。 数据采集是智慧农业的基础。通过手工录入、传感器自动采集、移动端录入、条码/RFID扫描录入、拍照录入以及GPS和遥感技术等多种方式,智慧农业系统能够全面收集农业生产过程中的各种数据。这些数据不仅包括环境参数,还涵盖了生长状态、加工保存、检验检疫等环节,为农业生产提供了全面的数据支持。 智慧农业的应用前景广阔,它不仅能够提升农业生产的管理水平,还能够通过各种应用系统,如库房管理、无公害监控、物资管理、成本控制等,为农业生产者提供全面的服务。此外,智慧农业还能够支持政府监管,通过发病报告、投入品报告、死亡报告等,加强农业产品的安全管理和质量控制。 面对智慧农业的建设和发展,存在一些挑战,如投资成本高、生产过程标准化难度大、数据采集和监测的技术难题等。为了克服这些挑战,需要政府、企业和相关机构的共同努力,通过政策支持、技术创新和教育培训等手段,推动智慧农业的健康发展。智慧农业的建设需要明确建设目的,选择合适的系统模块,并制定合理的设备布署方案,以实现农业生产的智能化、精准化和高效化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值