We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18373 ☆ A M B ☆
    • 3,141 Posts
    I'm not sure what that snippet does.. and is it right that when no radio button is selected it shows content?

    I'm really forced to guess stuff here and that never brings good results :/
      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
      • 37003
      • 12 Posts
      ok, will try start again.

      From the responses i used the link
      http://wiki.modxcms.com/index.php/Create_TV-Based_Chunks

      and have created the snippet etc to enable a user to check a radio button which then pulls in the code from a chunk to enable reusable content.

      Now i'm trying to expand that by allowing a manual override.

      So.
      If user selects the radio button -> show the contents on the chunk
      If user doesn't select a radio button -> show the content of a different chunk.

      So
      [[*rightNavBoxCheck1:empty=`[[$rightnav1]]`:notempty=`[[!chunkListParser]]`]]


      When i don't select a radio button is pulling in the correct chunk - i.e [[$rightnav1]]
      But if a user is selecting the radio button, nothing is displaying as per it was if i just placed
      [[!chunkListParser?chunks=`[[*rightNavBoxCheck1]]`]]
      which is showing correctly

      If i swap out the function for a different chunk just pulling it in, it displays.

      Hope that explains a bit more
        • 30912
        • 463 Posts
        It might be worth trying:

        [[*rightNavBoxCheck1:empty=`[[$rightnav1]]`:notempty=`[[!chunkListParser?chunks=`[[*rightNavBoxCheck1]]`]]`]]


        Your just calling [[!chunkListParser]] but your not passing anything TO the parser

        Alterantively try
         [[*rightNavBoxCheck1:empty=`[[$rightnav1]]`:notempty=`[[$CHUNK]]`]]


        where $CHUNK has
        [[!chunkListParser?chunks=`[[*rightNavBoxCheck1]]`]]
        in it - but i cant recall is chunks process snippets or not. [ed. note: Tyreal2012 last edited this post 15 years ago.]
          • 37003
          • 12 Posts
          So close, it's now calling the correct radio button, but when i don't select anything it's no longer showing.

          I've now swapped the logic round as per below
          [[*rightNavBoxCheck1:notempty=`[[!chunkListParser?chunks=`[[*rightNavBoxCheck1]]`]]`:empty=`[[$rightnav1]]`]]


          And at the moment it seems to be working. So i will continue to play around with it and do some more testing.

          Thanks again everyone. Just confirmed to me why i choose MODX as a CMS to learn.
            • 24732 ☆ A M B ☆
            • 300 Posts
            ah, you're trying to replicate the ChunkIf snippet? Attached. Might help. It is Evo but you can reproduce it.

            
            <?php
            
            	/*
            		Name: ChunkIf
            		Author: Duncan Lock <[email protected]>
            		Version: 0.2
            		Date: 21/07/2008
            		Description:
            			<strong>0.2</strong> Outputs the contents of the chunk passed in
            			$trueChunk if the template variable passed in $tv is set (i.e. has a value).
            			Otherwise outputs the contents of the $falseChunk chunk. Expects $tv to be the
            			name of the Template Variable to test, and $trueChunk & $falseChunk to be names
            			of chunks.
            	
            		eg:
            		
            		[[ChunkIf? &tv=`tvname` &trueChunk=`chunkname` &falseChunk=`chunkname` ]]
            			- Long version outputs $trueChunk if $tv has a value, otherwise 
            			outputs $falseChunk.
            		[[ChunkIf? &tv=`tvname` &trueChunk=`chunkname` ]]
            			- This short version outputs an empty string if $tv has no value.
            		[[ChunkIf? &tv=`tvname` ]]
            			- This very short version attempts to output the contents of a chunk
            			 with the same name as $tv
            		[[ChunkIf? &tv=`tvname` &debug=`1` ]]
            			- Switches on debugging output - output's HTML comments for debugging.
            	*/
            
            	// get tv name
            	$tv = isset( $tv ) ? $tv : '';
            
            	// get current page ID
            	$id = isset( $id )? $id: $modx -> documentObject['id'];
            
            	// Get the value of $tv
            	$tvarray = $modx -> getTemplateVarOutput( $tv, $id );
            	$value = ''.trim($tvarray[$tv]);
            
            	if ($debug) {
            		$dtmp = '<!--';
            		$dtmp .= 'tv: '.$tv.', ';
            		$dtmp .=  'id: '.$id.', ';
            		$dtmp .=  'value: '.$value;
            		$dtmp .=  '-->';
            
            		echo $dtmp;
            	}
            
            	// Decide which chunk to return.
            	if ($value == '') {
            		// get chunk to return if $tv has no value
            		$falseChunk = isset( $falseChunk )? $modx -> getChunk( $falseChunk ): '';
            		return $falseChunk;
            	} else {
            		// get chunk to return if $tv has a value
            		if (isset( $trueChunk ))
            		{
            			$trueChunk = $modx -> getChunk( $trueChunk );
            		} else {
            			// Attempt to get the chunk with the same name as $tv
            			$trueChunk = $modx -> getChunk( $tv );
            		}
            		
            		return $trueChunk;
            	}
            ?>
            
            
            
            
            
            
            




              ________

              Anne
              Toad-in-Chief
              Red Toad Media - Web Design, Louisville KY
              Hear me tweet: http://www.twitter.com/redtoadmedia
              "Bring on the imperialistic condiments." - Rory Gilmore