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);

See: http://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/class-reference/modx/modx.getchunk

[MODx] 8. Snippet get data, chunk display的更多相关文章

  1. TcxGrid 去除<No data to display>

  2. Data Binding in WPF

    http://msdn.microsoft.com/en-us/magazine/cc163299.aspx#S1   Data Binding in WPF John Papa Code downl ...

  3. 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 ...

  4. [转]Efficiently Paging Through Large Amounts of Data

    本文转自:http://msdn.microsoft.com/en-us/library/bb445504.aspx Scott Mitchell April 2007 Summary: This i ...

  5. 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 ...

  6. python chunk模块

    chunk模块用于读取TIFF格式的文件,打开应该使用二进制模式 TIFF 标签图像文件格式 import chunk import chunk f=open('E:\\test.tiff','rb' ...

  7. 运用模型绑定和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 ...

  8. ABAP术语-Data Browser

    Data Browser 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/21/1046858.html Tool for displayin ...

  9. 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 ...

随机推荐

  1. [原]Unity3D深入浅出 - 角色控制器(Character Controller)

    角色控制器主要用于第一人称和第三人称主角的控制,并不使用刚体物理效果. 添加角色控制器的方法:依次打开菜单栏中的Component - Physiscs - Character Controller ...

  2. UVa 1395 (最小生成树) Slim Span

    题意: 规定一棵生成树的苗条度为:最大权值与最小权值之差.给出一个n个顶点m条边的图,求苗条度最小的生成树. 分析: 按照边的权值排序,枚举边集的连续区间[L, R]的左边界L,如果这些区间刚好满足一 ...

  3. oracle 分组排序

    SELECT * FROM (SELECT A.*, RANK() OVER(PARTITION BY A.DR_ATP_ID, A.AT_CODE ORDER BY A.KEY_CODE) RANK ...

  4. 【转】UIColor对颜色的自定义

    原文网址:http://blog.sina.com.cn/s/blog_5f19ccb10101bhqh.html 在iOS开发中,我们使用UIColor来对我们的界面进行颜色设置,一般我们通过以下两 ...

  5. Android自定义控件步骤总结

    在android开发中,系统提供给我们的控件不能满足我们的需求,所以我们往往会自定义一些控件,在自定义过程中遵循以下几个步骤: 一.定义一个Class继承于系统View类 二.在xml文件中配置lay ...

  6. 仿酷狗音乐播放器开发日志三——修复CEditUI的bug2

    无意中发现了CEditUI控件的另一个bug,当我给播放器的搜索栏获取焦点时,这时再改变窗体大小,原本搜索栏应该对应着也改变大小,却发现CEditUI内嵌的edit控件没有跟着改变(如下图),跟着调试 ...

  7. win7下代替IDM的下载工具

    EagleGet 批量下载干刚刚的!!!!! 立马卸载IDM,哈哈哈 下载地址(免费软件) http://pan.baidu.com/s/1ntupiZJ

  8. #pragma once 与 #ifndef 解析(转载)

    正在入门驱动编程,遇到一个小问题,如下详细解释. 原文链接:#pragma once 与 #ifndef 解析 http://www.cnblogs.com/hokyhu/archive/2009/0 ...

  9. Linux 下文件名乱码(无效的编码)的解决办法

    文件是在WIndows 下创建的,Windows 的文件名中文编码默认为GBK,而Linux中默认文件名编码为UTF8,由于编码 不一致所以导致了文件名乱码的问题,解决这个问题需要对文件名进行转码. ...

  10. jquery chart plugin

    jquery flot http://www.jqueryflottutorial.com/ jquery jqplot http://www.jqplot.com/ highcharts中文网 : ...