Home  Extras  MODx Add-Ons  ChunkIf

Product:

ChunkIf


Forums Support Thread Votes: 109
Tags: snippet, chunk, template, output, switch
Submitted: Jan 6, 2009
Released: Jan 6, 2009
Downloads: 235
License: GPL - GNU Public
Package Website

Works with:

ChunkIf 0.2 | Author: dflock

ChunkIf allows you to choose which of two chunks gets output, based on a template variable being set or not.


Download


Description

Outputs the contents of a given chunk, if a given template variable is set, otherwise outputs the contents of a different chunk.

More info on my blog here: http://www.codeistry.com/blog/2008/11/modx-snippet-chunkif/

Instructions

In order to install this snippet, just paste the contents of ChunkIf.txt into a new Snippet in the manager called 'ChunkIf'.

The long form of the snippet call looks like this:
[[ChunkIf? &tv=`tvname` &trueChunk=`chunkname` &falseChunk=`chunkname` &debug=`1|0`]]

The parameters to the snippet call work like this:

&tv
This is the name of the template variable you want to test. The value of this variable will be checked and if itís not empty or blank, &trueChunk will be output - otherwise &falseChunk will be.
&trueChunk
The name of the chunk whoís content you want output, in the event that your template variable (&tv) has a value.
&falseChunk
The name of the chunk whoís content you want output, if your template variable (&tv) is empty. If you omit this paramater, an empty string will be output if &tv is empty.
&debug
Set this to 1 to emit debugging comments into the HTML output; set it to 0 or leave it out to switch off.

There is a short version too:

[[ChunkIf? &tv=`tvname`]]

The shorthand form attempts to output the contents of a chunk with the same name as &tv, if &tv is set, or an empty string. If thereís no chunk with the same name, it also returns an empty string.

This shorthand version is very handy for switching chunks on and off using a single variable. As chunks can contain other chunks and snippet calls, you can use this to switch sidebars, footers and other complex bits of layout on and off on a per page basis, with a simple checkbox template variable.




Released Versions

Releases that are grayed out are deprecated.

Version Released Author Downloads
Total Versions: 1 Total Downloads: 235
0.2 Jan 06, 2009 dflock 235

Download Statistics

Package downloads per day since tracking began on June 27th, 2010. Weekends are colored. Plot below shows an overview.


Top Countries

This is a list of the countries most downloading this Extra.

Country Downloads
United States 5
Japan 2
United Kingdom 1
Australia 1
 
 
 

Contact Us | Advertise | Team Blog | FAQ | Credits

© 2005-2010 MODx, LLC. All rights reserved. Privacy Policy | Terms of Service