[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是历史上最受欢迎的免费开源程序之一.它是成千上万个网站的数据库骨干,并且可以将它(和Linux)作为过去10年里Internet呈指数级增长的一个有力证明. 那么,如果MySQL真的这 ...
- [POJ 2429] GCD & LCM Inverse
GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10621 Accepted: ...
- I.MX6 gpio-keys driver hacking
/**************************************************************************** * I.MX6 gpio-keys driv ...
- 【转】Android.mk文件语法规范(Android.mk File)
原文网址:http://blog.csdn.net/smfwuxiao/article/details/8530742 1.Android.mk文件概述 Android.mk文件用来告诉NDK编译系统 ...
- (五)学习CSS之line-height属性
参考:http://www.jb51.net/w3school/css/pr_dim_line-height.htm line-height 属性设置行间的距离(行高). 注释:不允许使用负值. 值 ...
- SharePoint 2013 入门教程--系列文章
转:http://www.cnblogs.com/jianyus/p/3381415.html 以下文章是自己在学习SharePoint的过程中,不断积累和总结的博文,现在总结一个目录,分享给大家.这 ...
- LA 6540 Fibonacci Tree
以前做过的题···重新做一遍之后怎么做怎么wa···后来GG了···第二天看不知道为啥A了···难道我失忆了? 题意:无向图,边有黑色和白色两种颜色,求是否存在一个生成树中白边的个数是斐波那契数. 解 ...
- Jmeter初步使用--Jmeter安装与使用
由于jmeter是开源的性能测试工具,但是使用的人较少,网络上相关资料不全面,需要自己去揣摩,因此,小编就把自己在用Jmeter时的一些小结总结出来.而loadrunner工具是商业软件,网上通常都是 ...
- JSON 格式的转换: 数组、字符串、List集合、DataTable,实体对象
JSON验证工具:http://jsonlint.com/JSON简明教程:http://www.w3school.com.cn/json/Newtonsoft.Json类库下载:http://jso ...
- javaScript动态给下拉列表框添加选项
方式一: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></titl ...