<![CDATA[ "Inherit Selected Template" in Revolution? - My Forums]]> https://forums.modx.com/thread/?thread=50864 <![CDATA[Re: "Inherit Selected Template" in Revolution?]]> https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=4#dis-post-449848 sottwell Jan 08, 2013, 11:36 PM https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=4#dis-post-449848 <![CDATA[Re: "Inherit Selected Template" in Revolution?]]> https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=4#dis-post-449847
Thanks!]]>
taiyo1578 Jan 08, 2013, 11:32 PM https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=4#dis-post-449847
<![CDATA[Re:]]> https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-440897
Not when just applying a fc w/ constraint modResource.template=parenttemplate, nor w/ parent template choosen from drop down, nor w/ both.

Unfortunately the plugin from #p15 does not work as well (testedw fc deactivated).

It looks as if the fc sets do not work or produce just weird strange behavior. Right now I'm trying to find out if it is a caching issue in the manager because what actually happens is that I get the same template on every parent where I create a new resource even w/ different templates on different parents. As if the value for template is chached when fc sets are activated. When all fc sets are deactivated, I get at least the parent template as the choosen template on resource create.]]>
chris@crnm Oct 20, 2012, 05:04 PM https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-440897
<![CDATA[Re:]]> https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-435077 boundaryfunctions Aug 29, 2012, 08:53 AM https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-435077 <![CDATA[Re:]]> https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-435073 ram Aug 29, 2012, 07:58 AM https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-435073 <![CDATA[Re:]]> https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-433745
go to form customisation, create set of rules for your parent template, and inside, set default template id to child template

from now, when you use right click on document and select 'create new document here' it will have desired template set

cascade of templates is also possible this way - you simply need more rules

note:
there is a bug (probably, maybe I am missing something)
just setting template from dropdown does not work always as desired, I had whole array of strange events happeninng

to omit that, you need 2 'create' rules for each parent template:
'resource/create' action one with template chosen from dropdown
'resource/create' action without template (emty template) but constrainst set as follows:
modResource.template = 11
where 11 is id of your template

I have designed product catalogue with that and custom forms for entering products in backend. Works fantastic!]]>
rygar Aug 18, 2012, 08:52 AM https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-433745
<![CDATA[Re:]]> https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-429800
for example we have:
- res 1
---child 1
-------child 1

then i cr8
- res 1
---child 1
-------child 1
---child 2

it's okey, but if at once cr8
- res 1
---child 1
-------child 1
---child 2
-------child 1

plugin not work, its begin working only after clearing cache...

i solved it by plugin:
<?php
$modx->cacheManager->clearCache();

and set on OnDocFormSave

but thinking it can be solving anouther way...

the problem is in: when we cr8 resources there is not active checkbox "clear cache"..
how to set it to true?

any ideas?]]>
gaserge Jul 12, 2012, 09:47 PM https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-429800
<![CDATA[Re:]]> https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-411393 ]]> Hansek Feb 10, 2012, 06:07 AM https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-411393 <![CDATA[Re:]]> https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-407733 Little tutorial for this plugin at: http://www.jertix.org/en/blog/modx-revolution/modx-revolution-plugin-changetemplate.html

<?php
/**
* =========================
* ChangeTemplate
* =========================
*
* Plugin for MODX Revolution
* Set which template is inherited by children
* documents of a certain parent document
*
* Author:
* Marc Loehe (boundaryfunctions)
* marcloehe.de
*
* Modified by:
* Lorenzo Stanco <[email protected]>
* Lorenzostanco.com
*
* Usage:
*
* 1. Paste this as new plugin and connect it to system event
* 'OnDocFormRender'.
*
* 2. Assign a new TV 'changeTemplate' to each template
* for which you want to define the default children template.
*
* 3. Set the newly created TV to input type "Text"
*
* 4. Open a document and in the 'changeTemplate' TV type a
* comma separated list of template IDs.
*
* 5. Have fun!
*
*/
 
// Check Event
if ($modx->event->name == OnDocFormRender && $mode == modSystemEvent::MODE_NEW) {
   
  // Get current document ID
  if ($id = $_REQUEST['id']) {
 
    // Document Chain
    $resources = array($id);
 
    // Get parent ID
    foreach ($modx->getParentIds($id, 10, array('context' => $_REQUEST['context_key'])) as $parentId) {
      if ($parentId) array_push($resources, $parentId);
    }
     
    // Search changeTemplate in the chain
    $level = 0;
    $childTemplates = array();
    foreach ($resources as $resourceId) {
      $resource = $modx->getObject('modResource', $resourceId);
      if ($childTemplatesTV = $resource->getTVValue('changeTemplate')) {
         
        // Create template array for each tree level
        $childTemplates = @explode(',', $childTemplatesTV);
        if (empty($childTemplates)) break;
        foreach ($childTemplates as $k => $v) $childTemplates[$k] = intval(trim($v));
         
        break;
 
      }
 
      $level++;
 
    }
 
    // Set template based on tree level
    if (!empty($childTemplates)) {
      $useTemplate = $childTemplates[$level];
      if (!empty($useTemplate)) {
        
        // Set default template
        if (isset($modx->controller)) {
          $modx->controller->setProperty('template', $useTemplate);
        } else { // modX < 2.2.0
          $_REQUEST['template'] = $useTemplate;
        }
 
      }
    }
 
  }
 
}
]]>
microcipcip Jan 16, 2012, 03:38 PM https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-407733
<![CDATA[Re:]]> https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-406681
I'll report back in this thread when I find out how to set up correctly grandchildren templates and grand-grand children templates.]]>
microcipcip Jan 10, 2012, 09:52 AM https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-406681