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

    I'm looking for a custom template for Teleport, the great packaging toolkit for MODX Revolution https://github.com/modxcms/teleport.
    It's kind like the one named : resources.tpl.json with all assets, TVs, files... but without supplementing the existing ones. What I want to do is to get a complete dump that erase the resources of the destination profile.
    Is this possible ?
    Where can I find documentation for customizing tpls ?

    Any help would be greatly appreciated.
    Thanks
    JeanClaude

    This question has been answered by jchirschy. See the first response.

      • 29661
      • 116 Posts
      You can try to add this as first thing in the vehicles array in your tpl:

      {
              "vehicle_class": "xPDOScriptVehicle",
              "object": {
                  "source": "scripts\/truncate.tables.php",
                  "classes": ["modResource", "modTemplateVarResource", "modResourceGroupResource", "modContextResource"]
              },
              "attributes": {
                  "vehicle_class": "xPDOScriptVehicle"
              }
          }
      
        --
        John
        @theboxer
      • discuss.answer
        • 45206
        • 32 Posts
        Thanks theboxer.
        That did the trick, but I also have to modify resources.tpl.json by setting this :

        • set every "update_object": to true
        • set every "preserve_keys": to true
        That way, it keeps the original id and I've got a perfect copy of all the resources.

        To resume, the custom tpl is the following :
        {
            "name": "resources_complete",
            "vehicles": [
                {
                    "vehicle_class": "xPDOScriptVehicle",
                    "object": {
                        "source": "scripts\/truncate.tables.php",
                        "classes": ["modResource", "modTemplateVarResource", "modResourceGroupResource", "modContextResource"]
                    },
                    "attributes": {
                        "vehicle_class": "xPDOScriptVehicle"
                    }
                },
                {
                    "vehicle_class": "xPDOObjectVehicle",
                    "object": {
                        "class": "modResource",
                        "criteria": [
                            "1 = 1"
                        ],
                        "graph": {
                            "Template": [
        
                            ],
                            "ContentType": [
        
                            ],
                            "TemplateVarResources": {
                                "TemplateVar": [
        
                                ]
                            },
                            "ResourceGroupResources": {
                                "ResourceGroup": [
        
                                ]
                            },
                            "ContextResources": {
                                "Context": [
        
                                ]
                            }
                        },
                        "package": "modx"
                    },
                    "attributes": {
                        "preserve_keys": true,
                        "update_object": true,
                        "unique_key": [
                            "context_key",
                            "uri"
                        ],
                        "related_objects": true,
                        "related_object_attributes": {
                            "Template": {
                                "preserve_keys": true,
                                "update_object": true,
                                "unique_key": "templatename"
                            },
                            "ContentType": {
                                "preserve_keys": true,
                                "update_object": true,
                                "unique_key": "name"
                            },
                            "TemplateVarResources": {
                                "preserve_keys": true,
                                "update_object": true,
                                "unique_key": [
                                    "tmplvarid",
                                    "contentid"
                                ],
                                "related_objects": true,
                                "related_object_attributes": {
                                    "TemplateVar": {
                                        "preserve_keys": true,
                                        "update_object": true,
                                        "unique_key": "name"
                                    }
                                }
                            },
                            "ResourceGroupResources": {
                                "preserve_keys": true,
                                "update_object": true,
                                "unique_key": [
                                    "document_group",
                                    "document"
                                ],
                                "related_objects": true,
                                "related_object_attributes": {
                                    "ResourceGroup": {
                                        "preserve_keys": true,
                                        "update_object": true,
                                        "unique_key": "name"
                                    }
                                }
                            },
                            "ContextResources": {
                                "preserve_keys": true,
                                "update_object": true,
                                "related_objects": true,
                                "related_object_attributes": {
                                    "Context": {
                                        "preserve_keys": true,
                                        "update_object": true
                                    }
                                }
                            }
                        }
                    }
                }
            ]
        }


        And to get also every files in assets, you'll have to add this as first thing in the vehicles array :
                {
                    "vehicle_class": "xPDOFileVehicle",
                    "object": {
                        "source": "{+properties.modx.context_web_path}assets",
                        "target": "return MODX_BASE_PATH;"
                    },
                    "attributes": {
                        "vehicle_class": "xPDOFileVehicle"
                    }
                },
                {
                    "vehicle_class": "xPDOFileVehicle",
                    "object": {
                        "script": "extract\/basepathassets.php"
                    },
                    "attributes": {
                        "vehicle_class": "xPDOFileVehicle"
                    }
                },


        And then we get this custom tpl :
        {
            "name": "resources_complete",
            "vehicles": [
                {
                    "vehicle_class": "xPDOFileVehicle",
                    "object": {
                        "source": "{+properties.modx.context_web_path}assets",
                        "target": "return MODX_BASE_PATH;"
                    },
                    "attributes": {
                        "vehicle_class": "xPDOFileVehicle"
                    }
                },
                {
                    "vehicle_class": "xPDOFileVehicle",
                    "object": {
                        "script": "extract\/basepathassets.php"
                    },
                    "attributes": {
                        "vehicle_class": "xPDOFileVehicle"
                    }
                },        
                {
                    "vehicle_class": "xPDOScriptVehicle",
                    "object": {
                        "source": "scripts\/truncate.tables.php",
                        "classes": ["modResource", "modTemplateVarResource", "modResourceGroupResource", "modContextResource"]
                    },
                    "attributes": {
                        "vehicle_class": "xPDOScriptVehicle"
                    }
                },
                {
                    "vehicle_class": "xPDOObjectVehicle",
                    "object": {
                        "class": "modResource",
                        "criteria": [
                            "1 = 1"
                        ],
                        "graph": {
                            "Template": [
        
                            ],
                            "ContentType": [
        
                            ],
                            "TemplateVarResources": {
                                "TemplateVar": [
        
                                ]
                            },
                            "ResourceGroupResources": {
                                "ResourceGroup": [
        
                                ]
                            },
                            "ContextResources": {
                                "Context": [
        
                                ]
                            }
                        },
                        "package": "modx"
                    },
                    "attributes": {
                        "preserve_keys": true,
                        "update_object": true,
                        "unique_key": [
                            "context_key",
                            "uri"
                        ],
                        "related_objects": true,
                        "related_object_attributes": {
                            "Template": {
                                "preserve_keys": true,
                                "update_object": true,
                                "unique_key": "templatename"
                            },
                            "ContentType": {
                                "preserve_keys": true,
                                "update_object": true,
                                "unique_key": "name"
                            },
                            "TemplateVarResources": {
                                "preserve_keys": true,
                                "update_object": true,
                                "unique_key": [
                                    "tmplvarid",
                                    "contentid"
                                ],
                                "related_objects": true,
                                "related_object_attributes": {
                                    "TemplateVar": {
                                        "preserve_keys": true,
                                        "update_object": true,
                                        "unique_key": "name"
                                    }
                                }
                            },
                            "ResourceGroupResources": {
                                "preserve_keys": true,
                                "update_object": true,
                                "unique_key": [
                                    "document_group",
                                    "document"
                                ],
                                "related_objects": true,
                                "related_object_attributes": {
                                    "ResourceGroup": {
                                        "preserve_keys": true,
                                        "update_object": true,
                                        "unique_key": "name"
                                    }
                                }
                            },
                            "ContextResources": {
                                "preserve_keys": true,
                                "update_object": true,
                                "related_objects": true,
                                "related_object_attributes": {
                                    "Context": {
                                        "preserve_keys": true,
                                        "update_object": true
                                    }
                                }
                            }
                        }
                    }
                }
            ]
        }


        Is there any documentation that explains how to write correct tpl json file ?