[MODx] 8. Snippet get data, chunk display
Simple Example:
Lets process this chunk and output its value. We have this Chunk, called "WelcomeChunk":
<p>Welcome [[+name]]!</p>
We'll put this in our Snippet:
$output = $modx->getChunk('WelcomeChunk',array(
'name' => 'John',
));
return $output;
So every key in the associative array passed to the getChunk method corresponds to an available placeholder inside the chunk, e.g. [[+name]]
<p>Welcome John!</p>
Nested $properties
In our Chunk:
<a href="http://site.com/profile?user_id=[[+user.id]]!">User Details</a>
In our Snippet:
$output = $modx->getChunk('UserLink',array(
'user' => array('id' => 123)
);
return $output;
Parsing a String
Sometimes you need to parse a string using the MODX parser – this does not use getChunk, but it is related. Using the MODX parser is a bit slower than using a simple str_replace function, but it does let you use complex placeholders (e.g. to include another Chunk) and output filters etc. The trick is to create a temporary Chunk object, then run the process method on it.
// The formatting String
$tpl = 'Hello, my name is [[+name]]'; // Properties
$props = array('name' => 'Bob'); // Create the temporary chunk
$uniqid = uniqid();
$chunk = $modx->newObject('modChunk', array('name' => "{tmp}-{$uniqid}"));
$chunk->setCacheable(false); $output = $chunk->process($props, $tpl);
[MODx] 8. Snippet get data, chunk display的更多相关文章
- TcxGrid 去除<No data to display>
- Data Binding in WPF
http://msdn.microsoft.com/en-us/magazine/cc163299.aspx#S1 Data Binding in WPF John Papa Code downl ...
- Displaying Data in a Chart with ASP.NET Web Pages (Razor)
This article explains how to use a chart to display data in an ASP.NET Web Pages (Razor) website by ...
- [转]Efficiently Paging Through Large Amounts of Data
本文转自:http://msdn.microsoft.com/en-us/library/bb445504.aspx Scott Mitchell April 2007 Summary: This i ...
- Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 排序、筛选、分页以及分组
Sorting, filtering, paging, and grouping 7 of 8 people found this helpful By Tom Dykstra The Contoso ...
- python chunk模块
chunk模块用于读取TIFF格式的文件,打开应该使用二进制模式 TIFF 标签图像文件格式 import chunk import chunk f=open('E:\\test.tiff','rb' ...
- 运用模型绑定和web窗体显示和检索数据(Retrieving and displaying data with model binding and web forms)
原文 http://www.asp.net/web-forms/overview/presenting-and-managing-data/model-binding/retrieving-data ...
- ABAP术语-Data Browser
Data Browser 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/21/1046858.html Tool for displayin ...
- Table View Programming Guide for iOS---(四)---Navigating a Data Hierarchy with Table Views
Navigating a Data Hierarchy with Table Views 导航数据表视图层次 A common use of table views—and one to which ...
随机推荐
- mysql 查看表的类型
MySQL 数据表主要支持六种类型 ,分别是:BDB.HEAP.ISAM.MERGE.MYISAM.InnoBDB. 这六种又分为两类,一类是”事务安全型”(transaction-safe),包括B ...
- php 对象调用方法
static union _zend_function *zend_std_get_method(zval **object_ptr, char *method_name, int method_le ...
- SCOI2007修车
这样也行?这构图把我惊呆了: 把每个工人拆成N个点.记为A[i,j]表示第i个工人修倒数第j辆车. 每个车跟所有N*M个工人拆出的点连边.流量为1,费用为time[i,j]*k. 源和每辆车连边,N* ...
- NET下RabbitMQ实践[实战篇]
之前的文章中,介绍了如何将RabbitMQ以WCF方式进行发布.今天就介绍一下我们产品中如何使用RabbitMQ的! 在Discuz!NT企业版中,提供了对HTTP错误日志的记录功能 ...
- unix network programming(3rd)Vol.1 [第13~15章]《读书笔记系列》
第13章 守护进程和inetd 超级服务器 syslog() daemon_init() setuid() setgid() 第14章 高级IO 标准I/O函数库,支持3种缓冲 缓冲(读写存储设备(硬 ...
- AsyncEnumerableExtensions.cs z
public static class Extensions { public static async Task ForEachAsync<T, U>(this IEnumerable& ...
- nginx log_format指令记录自定义响应头
我们用的nginx有做过一些定制开发,为了调试方便,加了一些自定义的response header,那么如何把这个自定义头记录到日志中以便于观察呢? nginx log_format指令支持这种扩展, ...
- uva 2218 Triathlon
题意:铁人三项赛,给定每个选手游泳,自行车,赛跑三个阶段的平均速度,不知道每段比赛的路程,询问当前这个选手能否胜利. 思路:把题意转化为一个不等式,设比赛长度是1,如果i要战胜j,x.y分别是第一阶段 ...
- 了解常见的 Azure 灾难
以下内容涵盖多种不同类型的灾难情况.数据中心故障不是应用程序范围内发生故障的唯一原因.设计不良或管理错误也会导致中断.请在恢复计划的设计和测试阶段设想可能导致故障的原因,这样做很重要.一个好的计划可充 ...
- mysql日期加减问题
有一个date列,我想修改下,让该列里每个日期都加上7天,怎么写代码? update [表名] set date=date_add(date, interval 7 day); SELECT * f ...