We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15871
    • 105 Posts
    I have a TV that is using an @SELECT binding to generate a list of folder names.

    @SELECT pagetitle,id FROM modx_site_content WHERE deleted != 1 AND hidemenu != 1 AND parent = 47 ORDER BY `pagetitle` ASC 


    47 is the id of the main folder for all the product categries. This works successfully. But what I need to do is have the TV display in the manager when I am editing those folder’s children and default to the parent. Right now, it just defaults to the first item in the list.

    I have tried putting both of the following into the default field but it doesn’t work. in the manager, the don’t even render.

    @EVAL return $_GET['parent'];
    
    - or -
    
    @EVAL return $modx->documentObject['parent']; 
    


    What I am trying to do with this is create a TV that lists all the product categories and have the list default to the document’s parent (the product category) when I view the document (the product) in the manager.

    Any thoughts?
      • 34017
      • 898 Posts
      I would like to know that as well. I tried for a short time and couldnt get it to work either
        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
        • 4749
        • 623 Posts
        It works for me when I used the specific table and parent doc id like this:

        @SELECT menutitle FROM db1_site_content WHERE parent = 25

        I used menutitle to create the name in the dropdown, FROM the db table name and WHERE is the parent

        This way every doc that the user creates in that parent will show up as a selection in the tv dropdown. Sorry, I can’t get more technical than that. embarrassed
          The MODx has you...
          Utah Web Design
          • 4172
          • 5,888 Posts
          with this quick and dirty hack in ’mutate_content.dynamic.php’ about line 990 are the @bindings in TV-default-values processed in the manager:

              //removed $sql = "SELECT DISTINCT tv.*, IF(tvc.value!='',tvc.value,tv.default_text) as value ";
              $sql = "SELECT DISTINCT tv.*, tvc.value as value "; //new by Bruno
          
              $sql .= "FROM $dbase.`" . $table_prefix . "site_tmplvars` tv ";
              $sql .= "INNER JOIN $dbase.`" . $table_prefix . "site_tmplvar_templates` tvtpl ON tvtpl.tmplvarid = tv.id ";
              $sql .= "LEFT JOIN $dbase.`" . $table_prefix . "site_tmplvar_contentvalues` tvc ON tvc.tmplvarid=tv.id AND tvc.contentid = $id ";
              $sql .= "LEFT JOIN $dbase.`" . $table_prefix . "site_tmplvar_access` tva ON tva.tmplvarid=tv.id  ";
              $sql .= "WHERE tvtpl.templateid = " . $template . " AND (1='" . $_SESSION['mgrRole'] . "' OR ISNULL(tva.documentgroup)" . ((!$docgrp) ? "" : " OR tva.documentgroup IN ($docgrp)") . ") ORDER BY tvtpl.rank,tv.rank;";
                  $rs = mysql_query($sql);
                  $limit = mysql_num_rows($rs);
              if ($limit > 0) {
                      echo "<table style='position:relative' border='0' cellspacing='0' cellpadding='3' width='96%'>";
                  require ('tmplvars.inc.php');
                  require ('tmplvars.commands.inc.php');
          		require ('tmplvars.format.inc.php');// add by Bruno
                  for ($i = 0; $i < $limit; $i++) {
                          // go through and display all the document variables
                          $row = mysql_fetch_assoc($rs);
                      if ($row['type'] == 'richtext' || $row['type'] == 'htmlarea') { // htmlarea for backward compatibility
                              if (is_array($replace_richtexteditor))
                              $replace_richtexteditor = array_merge($replace_richtexteditor, array (
                                  "tv" . $row['name']
                              ));
                              else
                              $replace_richtexteditor = array (
                                  "tv" . $row['name']
                              );
                          }
                      // splitter
                      if ($i > 0 && $i < $limit)
                          echo '<tr><td colspan="2"><div class="split"></div></td></tr>';
                  ?>
                        <tr style="height: 24px;">
                          <td align="left" valign="top" width="150">
                              <span class='warning'><?php echo $row['caption']; ?></span><br /><span class='comment'><?php echo $row['description']; ?></span>
                          </td>
                          <td valign="top" style="position:relative">
                          <?php
          
                      $tvPBV = $_POST['tv' . $row['name']]; // post back value
          
          //add by Bruno
          if ($row['display'] !== 'unixtime'){
          $defaultOutput = getTVDisplayFormat($row['name'], $row['default_text'], $row['display'], $row['display_params'], $row['type'],$id);            	
          }
          // $defaultOutput=$row['default_text'];
          
                      echo renderFormElement($row['type'], $row['name'], $defaultOutput, $row['elements'], ($tvPBV ? $tvPBV : $row['value']), ' style="width:300px;"');
          
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 34017
            • 898 Posts
            Hey Bruno,

            What does that hack do?
              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
              • 4172
              • 5,888 Posts
              By default the @bindings @EVAL, @SELECT and so in the TV-default-value-field is not processed in the manager. With this hack it would.

              So if you have for your dropdown-list:

              @SELECT pagetitle,id FROM modx_site_content WHERE deleted != 1 AND hidemenu != 1 AND parent = 47 ORDER BY `pagetitle` ASC 


              you can have as default-value:

              @eval $parent=$modx->getParent($docid,0,'id');return $parent['id'];

              then the parent of the active document is selected in the dropdown-list by default.


              Perhaps this part needs some testing or some modifiing for your needs:
              //add by Bruno
              //$defaultOutput=ProcessTVCommand($row['default_text'], $row['name'], $id);
              if ($row['display'] !== 'unixtime'){
              $defaultOutput = getTVDisplayFormat($row['name'], $row['default_text'], $row['display'], $row['display_params'], $row['type'],$id);            	
              }
              else{
              $defaultOutput = ($row['value']!=='')?$row['value']:$row['default_text'];	
              }


              merry christmas
              Bruno
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 34017
                • 898 Posts
                and a beautiful christmas hack it is.

                thanks bruno
                  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
                  • 15871
                  • 105 Posts
                  Hi Bruno,
                  Is that file under manager/actions/

                  I’m on 9.6.2 and the code you referenced looks quite a bit different:

                  $template = $default_template;
                  	if (isset ($_REQUEST['newtemplate'])) {
                  		$template = $_REQUEST['newtemplate'];
                  	} else {
                  		if (isset ($content['template']))
                  			$template = $content['template'];
                  	}
                  
                  	$sql = 'SELECT DISTINCT tv.*, IF(tvc.value!=\'\',tvc.value,tv.default_text) as value '.
                  	       'FROM '.$tbl_site_tmplvars.' AS tv '.
                  	       'INNER JOIN '.$tbl_site_tmplvar_templates.' AS tvtpl ON tvtpl.tmplvarid = tv.id '.
                  	       'LEFT JOIN '.$tbl_site_tmplvar_contentvalues.' AS tvc ON tvc.tmplvarid=tv.id AND tvc.contentid=\''.$id.'\' '.
                  	       'LEFT JOIN '.$tbl_site_tmplvar_access.' AS tva ON tva.tmplvarid=tv.id '.
                  	       'WHERE tvtpl.templateid=\''.$template.'\' AND (1=\''.$_SESSION['mgrRole'].'\' OR ISNULL(tva.documentgroup)'.
                  	       (!$docgrp ? '' : ' OR tva.documentgroup IN ('.$docgrp.')').
                  	       ') ORDER BY tvtpl.rank,tv.rank';
                  	$rs = mysql_query($sql);
                  	$limit = mysql_num_rows($rs);
                  	if ($limit > 0) {
                  		echo "\t".'<table style="position:relative;" border="0" cellspacing="0" cellpadding="3" width="96%">'."\n";
                  		require(MODX_MANAGER_PATH.'includes/tmplvars.inc.php');
                  		require(MODX_MANAGER_PATH.'includes/tmplvars.commands.inc.php');
                  		for ($i = 0; $i < $limit; $i++) {
                  			// Go through and display all Template Variables
                  			$row = mysql_fetch_assoc($rs);
                  			if ($row['type'] == 'richtext' || $row['type'] == 'htmlarea') {
                  				// Add richtext editor to the list
                  				if (is_array($replace_richtexteditor)) {
                  					$replace_richtexteditor = array_merge($replace_richtexteditor, array(
                  						"tv" . $row['name'],
                  					));
                  				} else {
                  					$replace_richtexteditor = array(
                  						"tv" . $row['name'],
                  					);
                  				}
                  			}
                  			// splitter
                  			if ($i > 0 && $i < $limit)
                  				echo "\t\t",'<tr><td colspan="2"><div class="split"></div></td></tr>',"\n";
                  
                  			$tvPBV = array_key_exists('tv'.$row['name'], $_POST) ? $_POST['tv'.$row['name']] : $row['value']; // post back value
                  			echo "\t\t",'<tr style="height: 24px;"><td align="left" valign="top" width="150"><span class="warning">',$row['caption'],"</span>\n",
                  			     "\t\t\t",'<br /><span class="comment">',$row['description'],"</span></td>\n",
                  			     "\t\t\t",'<td valign="top" style="position:relative">',"\n",
                  			     "\t\t\t",renderFormElement($row['type'], $row['name'], $row['default_text'], $row['elements'], $tvPBV, ' style="width:300px;"'),"\n";
                  			     "\t\t</td></tr>\n";
                  		}
                  		echo "\t</table>\n";
                  	} else {
                  		// There aren't any Template Variables
                  		echo "\t<p>".$_lang['tmplvars_novars']."</p>\n";
                  	}