Skip to content

Instantly share code, notes, and snippets.

@Realetive
Forked from pepebe/getTVLabel.snippet.php
Last active August 29, 2015 14:16
Show Gist options
  • Save Realetive/caebdd2f3d279507b046 to your computer and use it in GitHub Desktop.
Save Realetive/caebdd2f3d279507b046 to your computer and use it in GitHub Desktop.
<?php
/*
Output filter to retrieve names of TVs from a list of TV ids
info@pepebe.de
Idea:
Use it with toogleTVSet plugin (included below) to handel different template options.
Usage:
This is a simple output filter.
You can use it in snippets like getResources or pdoTools to add TVs to your query:
Example:
&includeTVs=`[[*Header:getTVNames]]`
*/
$tvNames = array();
$tvIds = explode(',' ,$input);
foreach($tvIds as $tvId){
$tv = $modx->getObject('modTemplateVar', $tvId);
$tvNames[] = $tv->get('name');
}
$tvNames = implode(',',$tvNames);
return $tvNames;
<?php
/*
toggleTVSet plugin for modx v0.0.4 (2015-03-06 10:31)
info@pepebe.de
Changelog:
-----------------------------
v0.0.1 Initial release
v0.0.2 Corrected cut and paste mishap
v0.0.3 More cut and paste mishap (don't work in multiple tabs...)
v0.0.4 Minor changes to js to clean up code. New instructions
Todo:
-----------------------------
Add iterator to handle more than one group of TV Sets.
Usage:
------------------------------
1. Add plugin to modx manager.
2. Check OnDocFormPreRender Event
3. Setup Header TVs (Example):
* Standard_Headline (4)
* Jumbotron_BG_Color (5)
* Jumbotron_BG_Image (6)
* Jumbotron_RTE (7)
* Carousel_MIGX_TV (8)
* Cover_Background_Image (9)
* Cover_RTE (10)
4. Setup Select TV used for picking header type:
* Name: Header
* Type: Single Select TV
* Input Option Values: "Standard==4||Carousel==8||Cover==9,10||Jumbotron==5,6,7"
* Allow blank: false
* Enable typeahead: false
* Move it to the very top of your List of TVs
5. Done!
*/
$selectTV = "tv11"; // Add the id of your Header Single Select Here
/* No changes below this line. */
$js = "
Ext.onReady(function () {
function toggleTVSet(tvs,displayValue){
for(x in tvs){
if (typeof tvs[x] !== 'function') {
var tv = Ext.get('tv' + tvs[x] + '-tr');
tv.setStyle('display',displayValue);
}
}
console.log('toggleTVSet triggered tvs(' + tvs + ') set to display: ' + displayValue );
}
Ext.getCmp('modx-resource-tabs').on('tabchange',function(e){
if(e.getActiveTab().id == 'modx-panel-resource-tv'){
var selectTV = Ext.getCmp('".$selectTV."');
var hideTVs = selectTV.store.data.keys.join().split(',')
var showTVs = selectTV.getValue().split(',')
toggleTVSet(hideTVs , 'none');
toggleTVSet(showTVs , 'block');
selectTV.on('select',function(selectTV){
hideTVs = selectTV.store.data.keys.join().split(',')
showTVs = selectTV.getValue().split(',')
toggleTVSet(hideTVs , 'none');
toggleTVSet(showTVs , 'block');
});
}
});
});
";
$modx->regClientStartupHTMLBlock('<script>'.$js.'</script>');
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment