Hi,
I am trying to package up a custom template variable input option type (including the plugin and the associated smarty templates and controller code), And also in the package create a template variable based on this type at deployment time.
I can add the plugin and all the code necessary to create the input option but I can’t create the template variable, it doesn’t actually create. Is there anything special I need to do to create the template variable with a custom input option at the same time as installing that input option?
Any help would be apprecated and if you need more explanation pleased to give it.
Cheers,
Luke
Luke, take a look at the GetMyComponent package. There’s an example there of packaging TVs and attaching them to a template that may help.
Hi bobray,
Thanks for that already did, but I couldn’t see how they deployed both a custom template variable input option and created a template variable based on that option in the same package at the same time. I thought it would be as easy as specifying the type of the template variable to be the name of the input option but that doesn’t seem to work unless I am missing something.
Appreciate the Help.
Cheers,
Luke
Luke, take a look at install.script.php in the _build/resolvers directory. I think you would have to do it there.
Sorry I am probably not explaining myself properly, I am not using the GetMyComponent package, but have built my own transport package build directory that does most things I need perfectly, The issue is I don’t know how to specifically create a template variable based on a custom input option in the same package as registering the plugin for that input option
(i.e. plugin that handles OnDocFormPreRender and OnTVInputRenderList)
so that it appears as a template variable within the system once installed.
What would be the build directives I would need to put in to the system to accommodate it, for a normal template variable I would have the following
$tvs[2]= $modx->newObject(’modTemplateVar’);
$tvs[2]->fromArray(array(
’id’ => 2,
’name’ => ’ProductCode’,
’description’ => ’The code of this product (could be a stock keeping part number)’,
’type’ => ’textbox’,
’display’ => ’default’,
’caption’ => ’Product Code’
),’’,true,true);
Cheers,
Luke
Sorry, some people call all TVs "custom TVs."
I’ve never created a true custom TV, but I suspect that creating it is exactly as you suggest, but with a few more fields. I’m pretty sure you can take a look at the TV in PhpMyAdmin and use the procedure you’ve described above but with the other fields included. If any of the fields are JSON arrays, you likely have the option of using $tv->set() on them with a regular PHP array as an argument and xPDO will do the conversion automatically. If so, it will also convert the other way on $tv->get();.