We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5340
    • 1,624 Posts
    Hi guys,

    I was not able to find a plugin that lets me specify in the container, what child I want to use for the children.
    So here is my implementation

    
    /*
     * Template to Children
     *
     * Children will inherit the template specified in the 
     * TplToChild TV. Use it for any container that you need 
     * to specify a diffrent template than the parent
     *
     * Configuration:
     * check the OnDocFormPrerender event
     *			make sure this plugin is called after Inherit parent Template plugin
     *
     * create a TV named TplToChild, 
     * 				Input Type:  DropDown List menu
     * 				Input Option Values:  @SELECT templatename, id FROM [+PREFIX+]site_templates
     * Choose the templates you would use it for
     *
     * Version 0.2
     *
     * based on Inherit Template Plugin
     */
    global $content;
    $e = &$modx->Event;
    
    switch($e->name) {
      case 'OnDocFormPrerender':
        if(($_REQUEST['pid'] > 0) && ($id == 0)) {
    			
    			$sql = "SELECT * FROM ".$modx->db->config['table_prefix']."site_tmplvars tvvar JOIN ".$modx->db->config['table_prefix']."site_tmplvar_contentvalues tvcv ON tvvar.id = tvcv.tmplvarid AND tvcv.contentid = '".$_REQUEST['pid']."' WHERE name = 'TplToChild'";
    			
    			$rs= $modx->dbQuery($sql);
    			$row = $modx->fetchRow($rs);
    			
    			if(isset($row['value'])){
    				$content['template'] = $row['value'];
    			}
    		}
    	break;
    
      default:
        return;
        break;
    }
    


    Let me know if this kind of plugin was published before or if there is the need to add it to the repository


    Thx
      • 6726
      • 7,075 Posts
      It’s just what I need, thanks !
      I’ll try it out and give some feedback later this week...

      My take is, publish it in the repo, even if it’s a variant of what already exist it could fit better someone’s particular need
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l'outil id
        • 7231
        • 4,205 Posts
        Here is a similar one. I will be using one of these solutions in the next project for sure. grin
        http://modxcms.com/forums/index.php/topic,21150.msg130700.html#msg130700
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don't know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 6726
          • 7,075 Posts
          I saw this other one but thought it was a refined version, isn’t it ?
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l'outil id
            • 5340
            • 1,624 Posts
            Are talking about automaticTpl?

            http://modxcms.com/forums/index.php/topic,28071.msg171228.html#msg171228

            This is a new version that is already in repository