[MODx] 8. Snippet get data, chunk display

Source: Internet
Author: User
Tags modx

Simple Example:

Lets process this chunk and output its value. We have this Chunk, called "Welcomechunk":

< P > Welcome [[+name]]! </ P >

We ' ll put this on 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 Insid e the chunk, e.g. [[+name]

< P > Welcome john! </ P >

Nested $properties

In our Chunk:

<href= "http://site.com/profile?user_id=[[+user.id]]!" > User Details</a>

In our Snippet:

$output $modx->getchunk (' Userlink ',   Array (' id ' = + 123);  return $output;

parsing a String

Sometimes you need to parse a string using the MODX parser–this does isn't use GetChunk, but it's related. Using the MODX parser is a bit slower than using a simple str_replace function, but it does let's use complex Placeholde RS (e.g to include another Chunk) and output filters etc. The trick is to create a temporary Chunk object and 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.