Template


 1  页面元素

The dot operator '.' is used to access into lists and hashes or to call object methods. The FOREACH directive is provided for iterating through lists, and various logical tests are available using directives such as IF, UNLESS,

 

[% FOREACH section = menu %]
   <a href="[% root %]/[% section %]/index.html">[% section %]</a>
[% END %]

<b>Client</a>: [% client.name %] (id: [% client.id %])

[% IF shopcart.nitems %]
   Your shopping cart contains the following items:
   <ul>
   [% FOREACH item = shopcart.contents %]
     <li>[% item.name %] : [% item.qty %] @ [% item.price %]
   [% END %]
   </ul>

   [% checkout(shopcart.total) %]

[% ELSE %]
   No items currently in shopping cart.
[% END %]
 2  [% mode == 'graphics' ? "Graphics Mode Enabled" : "Text Mode" %]
[% var = 'value' IF some_condition %]

 3  取值不需要加符号,直接引用变量名,字符串连接用‘_’
[% copyright = '(C) Copyright' _ year _ ' ' _ author %]
等同于
[% copyright = "(C) Copyright $year $author" %]
 4  默认值
The DEFAULT directive is similar to SET but only updates variables that are currently undefined or have no "true" value (in the Perl sense). 
[% DEFAULT 
   title = 'Hello World'
   bgcol = '#ffffff'
%]
<html>
  <head>
    <title>[% title %]</title>
  </head>
  <body bgcolor="[% bgcol %]">
    ...etc...
 5  条件处理
 5.1  IF / UNLESS / ELSIF / ELSE
[% IF age < 10 %]
   Hello [% name %], does your mother know you're 
   using her AOL account?
[% ELSIF age < 18 %]
   Sorry, you're not old enough to enter 
   (and too dumb to lie about your age)
[% ELSE %]
   Welcome [% name %].
[% END %]
== != < <= > >= && || ! and or not

 5.2  SWITCH / CASE
[% SWITCH myvar %]
[%   CASE 'value1' %]
       ...
[%   CASE ['value2', 'value3'] %]   # multiple values
       ...
[%   CASE myhash.keys %]            # ditto
       ...
[%   CASE %]                        # default
       ...
[% END %]

 5.3  FOREACH
[% foo   = 'Foo'
   items = [ 'one', 'two', 'three' ]
%]

Things:
[% FOREACH thing IN [ foo 'Bar' "$foo Baz" ] %]
   * [% thing %]
[% END %]

Items:
[% FOREACH i IN items %]
   * [% i %]
[% END %]

Stuff:
[% stuff = [ foo "$foo Bar" ] %]
[% FOREACH s IN stuff %]
   * [% s %]
[% END %]
You can use also use = instead of IN if you prefer. [% FOREACH i = items %]
[% userlist = [
    { id => 'tom',   name => 'Thomas'  },
    { id => 'dick',  name => 'Richard'  },
    { id => 'larry', name => 'Lawrence' },
   ]
%]

[% FOREACH user IN userlist %]
   [% user.id %] [% user.name %]
[% END %]
short form: 
[% FOREACH userlist %]
   [% id %] [% name %]
[% END %]

[% users = {
     tom   => 'Thomas',
     dick  => 'Richard',
     larry => 'Lawrence',
   }
%]
[% FOREACH u IN users %]
   * [% u.key %] : [% u.value %]
[% END %]

 5.4  NEXT: The NEXT directive starts the next iteration in the FOREACH loop. 
[% FOREACH user IN userlist %]
   [% NEXT IF user.isguest %]
   Name: [% user.name %]    Email: [% user.email %]
[% END %]

LAST: The LAST directive can be used to prematurely exit the loop. BREAK is also provided as an alias for LAST. 
[% FOREACH match IN results.nsort('score').reverse %]
   [% LAST IF match.score < 50 %]
   [% match.score %] : [% match.url %]
[% END %]

 5.5  The FOREACH directive is implemented using the Template::Iterator module. A reference to the iterator object for a FOREACH directive is implicitly available in the loop variable. The following methods can be called on the loop iterator. 
size()      number of elements in the list
max()       index number of last element (size - 1)
index()     index of current iteration from 0 to max()
count()     iteration counter from 1 to size() (i.e. index() + 1)
first()     true if the current iteration is the first
last()      true if the current iteration is the last
prev()      return the previous item in the list
next()      return the next item in the list

[% FOREACH item IN [ 'foo', 'bar', 'baz' ] -%]
   [%- "<ul>\n" IF loop.first %]
   <li>[% loop.count %]/[% loop.size %]: [% item %]
   [%- "</ul>\n" IF loop.last %]
[% END %]
[% FOREACH group IN grouplist;
     # loop => group iterator
     "Groups:\n" IF loop.first;
     FOREACH user IN group.userlist;
        # loop => user iterator
        "$loop.count: $user.name\n";
     END;
     # loop => group iterator
     "End of Groups\n" IF loop.last;
   END 
%]

 5.6  WHILE
The NEXT directive can be used to start the next iteration of a WHILE loop and BREAK can be used to exit the loop, both as per FOREACH. 

[% WHILE total < 100 %]
   ...
   [% total = calculate_new_total %]
[% END %]
[% WHILE (user = get_next_user_record) %]
   [% user.name %]
[% END %]

 6  FILTER: described in Template::Manual::Config
 6.1  The html filter, for example, escapes the '<', '>' and '&' characters to prevent them from being interpreted as HTML tags or entity reference markers. 
The html filter is an example of a static filter, implemented as: 
sub html_filter {
    my $text = shift;
    for ($text) {
        s/&/&amp;/g;
        s/</&lt;/g;
        s/>/&gt;/g;
    }
    return $text;
}
 6.2  Dynamic filters can accept arguments which are specified when the filter is called from a template. The repeat filter is such an example, accepting a numerical argument which specifies the number of times that the input text should be repeated. 
[% FILTER repeat(3) %]blah [% END %]
output: 
blah blah blah
The repeat filter factory is implemented like this: 
sub repeat_filter_factory {
    my ($context, $iter) = @_;
    $iter = 1 unless defined $iter;

    return sub {
        my $text = shift;
        $text = '' unless defined $text;
        return join('\n', $text) x $iter;
    }
}
 7  META
it's not possible to interpolate other variables values into META variables.
The template variable contains a reference to the main template being processed. These metadata items may be retrieved as attributes of the template. 

[% META
   title   = 'The Cat in the Hat'
   author  = 'Dr. Seuss'
   version = 1.23 
%]
<h1>[% template.title %]</h1>
<h2>[% template.author %]</h2>

本项目采用C++编程语言结合ROS框架构建了完整的双机械臂控制系统,实现了Gazebo仿真环境下的协同运动模拟,并完成了两台实体UR10工业机器人的联动控制。该毕业设计在答辩环节获得98分的优异成绩,所有程序代码均通过系统性调试验证,保证可直接部署运行。 系统架构包含三个核心模块:基于ROS通信架构的双臂协调控制器、Gazebo物理引擎下的动力学仿真环境、以及真实UR10机器人的硬件接口层。在仿真验证阶段,开发了双臂碰撞检测算法和轨迹规划模块,通过ROS控制包实现了末端执行器的同步轨迹跟踪。硬件集成方面,建立了基于TCP/IP协议的实时通信链路,解决了双机数据同步和运动指令分发等关键技术问题。 本资源适用于自动化、机械电子、人工智能等专业方向的课程实践,可作为高年级课程设计、毕业课题的重要参考案例。系统采用模块化设计理念,控制核心与硬件接口分离架构便于功能扩展,具备工程实践能力的学习者可在现有框架基础上进行二次开发,例如集成视觉感知模块或优化运动规划算法。 项目文档详细记录了环境配置流程、参数调试方法和实验验证数据,特别说明了双机协同作业时的时序同步解决方案。所有功能模块均提供完整的API接口说明,便于使用者快速理解系统架构并进行定制化修改。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值