We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34017
    • 898 Posts
    It would be great to hide some TVs based on the parent. Here’s an example:

    Products (3)
    - Book Category (4)
    - Great Gadsby
    - Enders Game

    - DVD Category (5)
    - Gran Torino
    - Fried Green Tomatoes

    All of the above documents share the same template. It would be great to be able to say hideFields(list_of_tvs_, parent=3)

    Does that make sense or seem doable?
      Chuck the Trukk
      ProWebscape.com :: Nashville-WebDesign.com
      - - - - - - - -
      What are TV's? Here's some info below.
      http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
      http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
      • 23762
      • 2 Posts
      I too would like to know how this is done.

      In my case I would like to hide fields for pages with certain parents, or perhaps based on certain templates?
        • 25969
        • 118 Posts
        Me too. Sure I could create another template but if this is doable with MM (hiding TVs based on parent) then keeping templates to a minimum would be great too.
        • You could use a user group/document group pair to hide them.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 21610
            • 360 Posts
            It would be very helpful if the rules could be attached not to the template, but to the document id
              Разработка сайтов на MODx
              • 13481
              • 97 Posts
              I wrote this today. Copy and paste code into managermanager/functions/fieldvalues.inc.php

              //---------------------------------------------------------------------------------
              // mm_conditional
              // Set Value based on a parent value values from a parent
              //---------------------------------------------------------------------------------
              function mm_conditional($fields, $value, $parentvalue, $conditional='IS', $roles='', $templates='') {
              
              	global $mm_fields, $modx;
                
              	$e = &$modx->Event;
              	
              	// if we've been supplied with a string, convert it into an array 
              	$fields = makeArray($fields);
              	
                $output = " // ----------- Conditional -------------- \n";
                
              	// if we aren't creating a new document or folder, we don't want to do this
              	//if (!($modx->manager->action == "85" || $modx->manager->action == "4")) {
              	//	return;
              	//} 
              	
              	// Are we using this rule?
              	if (useThisRule($roles, $templates)) {
              	
              		//$output = " // ----------- Inherit -------------- \n";
              	
              		// Get the parent info
              		if (isset($_REQUEST['id'])){
              			$parentID = $modx->getPageInfo($_REQUEST['id'],0,'parent');
              			$parentID = $parentID['parent'];
              		} else {
              			$parentID = 0;
              		}
              		
              		foreach ($fields as $field) { 
              			switch ($field) {
              						
              				default:
              				
              					// get some info about the field we are being asked to use
              					if (isset($mm_fields[$field])) {
              						$fieldtype = $mm_fields[$field]['fieldtype'];
              						$fieldname = $mm_fields[$field]['fieldname'];
              					} else {
              						break;
              					}
              				
              					// Get this field data from the parent
              					$newArray = $modx->getDocument($parentID, $field);
              					$newvalue = $newArray[$field];
                        
                        $output .= "\n// --- $fieldtype ---\n";
                                  
                        if ($conditional == 'IS')
                        {
                          $output .=  "\n// --- IS: $newvalue == $parentvalue ---\n";
                          if ($newvalue == $parentvalue)
                          {
                              $output .=  '$("'.$fieldtype.'[@name='.$fieldname.']").val("' . jsSafe($value) . '");';
                          }
                          else
                          {
                            $output = '';
                          }
                        }
                        elseif($conditional == 'ISNOT')
                        {
                          if ($newvalue != $parentvalue)
                          {
                              $output .=  '$("'.$fieldtype.'[@name='.$fieldname.']").val("' . jsSafe($value) . '"); ';
                          }
                          else
                          {
                            $output = '';
                          }
                        }
                        else
                        {
                          $output = '';
                        }
              					
              				break;	
              			}	
              			$e->output($output . "\n");
              		}		
              	}
              }


              Use like:

              mm_conditional('template',9,10); // if the parent template is 10, it will change this template to 9. Unfortunately it will not get any of the managermanager attributes for the new template.
              

              or

              mm_conditional('pagetitle','This is a sub news document','News');  // if the pagetitle is news, set this pagetitle to 'This is a ...'


              I haven’t tested it a lot and it didn’t work out for how I wanted to use it (to automatically set the template of child documents to a different template than the parent...AND get the manager manager attributes for the new template).

              Hope this helps someone else.

              James


                • 34017
                • 898 Posts
                Hey James,

                Thanks man. Love the DevTrench blog too.

                Chuck
                  Chuck the Trukk
                  ProWebscape.com :: Nashville-WebDesign.com
                  - - - - - - - -
                  What are TV's? Here's some info below.
                  http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                  http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
                  • 21056
                  • 327 Posts
                  Quote from: ChuckTrukk at Jan 26, 2009, 11:27 AM

                  It would be great to hide some TVs based on the parent. Here’s an example:

                  Products (3)
                  - Book Category (4)
                  - Great Gadsby
                  - Enders Game

                  - DVD Category (5)
                  - Gran Torino
                  - Fried Green Tomatoes

                  All of the above documents share the same template. It would be great to be able to say hideFields(list_of_tvs_, parent=3)

                  Does that make sense or seem doable?

                  I don’t think it’s easily achievable at the moment, but with some of the changes I’ve got planned for the next version, it should be feasible.

                  I’ll log it in Jira so it doesn’t get forgotten - http://svn.modxcms.com/jira/browse/ADDON-67
                    Author: ManagerManager plugin - customise your ModX manager interface

                    Rckt - web development, Sheffield, UK
                    • 5340
                    • 1,624 Posts
                    Try this

                    http://modxcms.com/forums/index.php/topic,38684.0.html

                    You will need to define a chunk for the parent. Enter: 100[100] This means that 100 will be the template of the document and only the 100 template will shown in the dropdown.