XML Import - Setting a template for content container


(Ian Hirst) #1

Matrix Version:5.4.3.1
Using this xml with the ‘Import Assets from XML’ tool…
<actions> <action> <action_id>set_Bodycopy_Div_attributes</action_id> <action_type>set_attribute_value</action_type> <asset>261176</asset> <attribute>attributes</attribute> <value><![CDATA[array ( 'identifier' => 'Map', 'layout_type' => 'none', 'css_class' => '', 'content_type' => 'content_type_wysiwyg', 'template' => '206395' );]]></value> </action> <action> <action_id>set_Bodycopy_Div_template_applied</action_id> <action_type>set_attribute_value</action_type> <asset>261176</asset> <attribute>template_applied</attribute> <value><![CDATA[true]]></value> </action> </actions>

and it does apply those details to the content container…

image

However, it does not update the ‘Template’ field on the ‘Details’ screen for the content container:

image

As this has not been updated, the various schemas and layouts associated with the container template are not applied and we have to go in and do this manually.

Is there a way to set the ‘Template’ field on the details screen via the xml, webservice or trigger?


(John gill) #2

To the best of my knowledge (i.e. it has worked for me so far, but there might be implications I haven’t tripped over yet), there are four things you need to do to properly recreate what happens when you add a template (CCT from here on) manually.

  1. Set the Metadata Schema on the container
  2. Create a NOTICE link with value container_template between container and CCT
  3. Set the attributes attribute on the container with the 'template' => '<CCT ID>' property
  4. Set the template_applied attribute on the container to 1

(As far as I know, the only one that isn’t required is the attributes attribute from your example. Everything seems to work without it, but I’d include it to better match the real thing.)

There might be other requirements if you use a Simple Edit Layout. I try not to use them, so I’m not sure.

An example of an import XML trying to apply a CCT (#527) to container (#566) :

<?xml version="1.0" encoding="utf-8"?>
<actions>

<action>
   <action_id>attr_attributes</action_id>
   <action_type>set_attribute_value</action_type>
   <asset>566</asset>
   <attribute>attributes</attribute>
   <value><![CDATA[array (
  'content_type' => 'content_type_wysiwyg',
  'layout_type' => 'div',
  'container_id' => 'content_container_manual',
  'desc' => '',
  'css_class' => '',
  'use_custom_id' => '',
  'template' => '527',
  'disable_keywords' => '',
  'dir' => '',
);]]></value>
</action>

<action>
   <action_id>attr_template_applied</action_id>
   <action_type>set_attribute_value</action_type>
   <asset>566</asset>
   <attribute>template_applied</attribute>
   <value><![CDATA[1]]></value>
</action>

<action>
   <action_id>cct_link</action_id>
   <action_type>create_link</action_type>
   <asset>527</asset>
   <assetid>566</assetid>
   <is_major>0</is_major>
   <link_type>8</link_type>
   <value>container_template</value>
   <is_dependant>0</is_dependant>
   <is_exclusive>0</is_exclusive>
</action>

<action>
   <action_id>set_schema</action_id>
   <action_type>set_metadata_schema</action_type>
   <asset>566</asset>
   <schemaid>536</schemaid>
   <granted>1</granted>
   <cascades>1</cascades>
</action>

</actions>

(Ian Hirst) #3

Brilliant, thanks John, that has worked for me. :grinning: