I have a very simple site that I want to manage via a single template and conditionals, but TV in use vary by resource.
This is probably a dumb question, but is there a way to restrict access of a TV to a template based on something other than the template itself?
Thanks...
-
☆ A M B ☆
- 24,524 Posts
There are some conditions you can use to show/hide a TV in Form Customization, but resource ID is unfortunately not one of them - or at least I haven't been able to get it to work with resource ID.
TV's can be hidden away during edit by:
- access permissions (the most simple way is create a new mgr user)
- manager customization
- being replaced by xPDO objects
http://bobsguides.com/blog.html/2014/06/02/why-extend-modresource/
But what do you want to accomplish?
Yes and I didn't know Bob had a blog post on my idea -->
http://bobsguides.com/blog.html/2013/10/24/hiding-modx-top-menu-items-from-some-users/
This way you could categorize the TV's to pages (resource groups) and set users for each group.
If there are no security concerns, you may want to use something like this...
Cheers,
pepebe
<?php
/**
* Hide TVs for root elements...
*/
/* Set option(s) here */
$tvs_to_hide = '1,2';
/* ---------------------------------- */
$parentId = $resource->get('parent');
if($parentId == 0){
switch($modx->event->name){
case 'OnDocFormRender':
$html = "
<script type='text/javascript'>
Ext.onReady(function () {
console.log('Parent id is 0 - Hide some TVs from user');
var tvs_to_hide = [".$tvs_to_hide."];
Ext.each(
tvs_to_hide,
function(tv_to_hide, index) {
var tv = Ext.get('tv' + tv_to_hide + '-tr');
if(tv){
console.log('tv' + tv_to_hide + ' found and hidden');
tv.setVisibilityMode(Ext.Element.DISPLAY).hide();
}
else{
console.log('tv' + tv_to_hide + ' cannot be found');
}
}
);
});
</script>
";
$modx->regClientStartupHTMLBlock($html);
break;
default:
break;
}
return;
}
else {
return;
}
/**/