-
- 1,145 Posts
So you read this
http://tracker.modx.com/issues/1852
and this
https://forums.modx.com/thread/77178/check-to-see-if-resource-id-exists-as-a-template-variable-value-in-snippet-call
and even this
http://bobsguides.com/blog.html/2014/04/09/get-tv-values-the-fast-way/
And you are still scratching your head?
Yea, me too... I scratched my beard bald!
- I have a plugin that must fire only if a resource has a template to which is attached a particular TV
- This resource will have its own value in the TV, filled or empty
- This TV must have a default_value
- I have the TV name and resource ID that's all
A Perfectly Working Exampleif ($modxEventName == 'OnDocFormPrerender') {
$tvName = $modx->getObject('modTemplateVar', array('name' =>'tvNAME')); // you could wrap this with an IF before you continue
$tvId = $tvName->get('id');
$tvValue = $resource->getTVValue($tvId);
$tvTemplateId = $modx->getObject('modTemplateVarTemplate', array("tmplvarid" => $tvId))->get("templateid");
$resourceTemplateId = $resource->get("template");
if ($tvValue || $tvValue == ''){
if ($tvTemplateId == $resourceTemplateId) {
//do stuff
}
}
}
Cheers,
what's in a name?
[ed. note: donshakespeare last edited this post 8 years, 2 months ago.]
TinymceWrapper: Complete back/frontend content solution.
Harden your MODX site by
passwording your three main folders:
core, manager, connectors and renaming your
assets (thank me later!)
5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
-
- 5,888 Posts
one joined query, could also work, something like that(untested):
<?php
$tvname = 'TVname';
$c = $modx->newQuery('modTemplateVar');
$c->leftjoin('modTemplate','TemplateVarTemplates');
$c->leftjoin('modTemplateVarResource','TemplateVarResources');
$c->select($c->xpdo->getSelectColumns('modTemplateVar','modTemplateVar', ''));
$c->select($c->xpdo->getSelectColumns('modTemplateVarResource','TemplateVarResources', 'tvvalue_'));
$c->where(array(
'TemplateVarResources.contentid'=>$resource->get('id'),
'modTemplateVar.name'=>$tvname,
'TemplateVarTemplates'=>$resource->get('template')
));
if ($tv = $modx->getObject('modTemplateVar',$c)){
$value = $tv->get('tvvalue_value');
$default = $tv->get('default_text');
//do stuff
}