MODX Community

Snippet doesn't work [Help needed]

Hi,

I have a resource page (Id 35) where I assign TV-related content. It works fine but after installing babel and uninstall suddenly when I do a snippet call it doesn’t work anymore!

The Snippet name is: getSiteRelatedData (Returns the value of the tv determined by the argument $id on the SiteRelated Document of the current context

<?php
if($tv != ''){

	$params['resourceId'] = 35;
	$params['contextKey'] = $modx->context->key;
	$params['showUnpublished'] = 0;

	$siteRelatedId = $modx->runSnippet("BabelTranslation", $params);

	$resource = $modx->getObject('modResource',array(
		'id' => $siteRelatedId
	));

	return $modx->resource->getTVValue($tv);
}else{
	return 'false';
}

CHUNK Call

[[getSiteRelatedData? &tv=`EmailTo`]]

(older TV woks fine)

But when I create a new TV it doesn’t show up.
The template access is correct and all other settings are the same.

What can be wrong?

Please advice. Many thanks

Environment

MODX version: 2.7.1
NGNIX ModxCloud

If you’ve uninstalled babel I suspect this line maybe the problematic one.

$siteRelatedId = $modx->runSnippet("BabelTranslation", $params); 

Hi, Thanks for helping. But still not working.

And after all, other TVs are working correctly if I use the snippet.

Also when I install again Babel doesn’t work. :frowning:

I’m not familiar with the babel extra but the snippet you posted requires a snippet called BabelTranslation. Does this snippet still exist if you uninstalled Babel? I suspect not unless it’s a custom snippet you wrote?

Hi, It’s a custom snippet.

Did the problem begin with installing Babel? It seems you would have had babel installed for it to work. Could that BabelTranslation snippet been changed, and then overwritten when re-installing Babel?

Be sure you’re not logged in to the Manager when testing this. When looking at the front-end while logged in to the Manager, the $modx->context->key will be ‘mgr’ which would probably make the snippet fail (unless you’ve explicitly logged in to the front end).

You might add this after you set the params as a diagnostic:

$modx->log(modX::LOG_LEVEL_ERROR, 'CONTEXT: ' . $params['contextKey']);

You could also try:

$params['contextKey'] = $modx->context->get('key');

though I don’t think it will make any difference.

Be sure to initialize $params as an empty array before setting the members if you’re not doing that already:

$params = array();

<?php
if($tv != ''){
	$params['resourceId'] = 35;
	$params['contextKey'] = $modx->context->key;
	$params['showUnpublished'] = 0;

	$siteRelatedId = $modx->runSnippet("BabelTranslation", $params);

	$resource = $modx->getObject('modResource',array(
		'id' => $siteRelatedId
	));


	return $modx->resource->getTVValue($tv);
}else{
	return 'false';
}
1 Like

I think you want:

return $resource->getTVValue($tv);
1 Like