0
votes

I am strugling to get resource ID based on context with babelTranslation?

Here is my example

[[!getContext]]
[[BabelTranslation? &contextKey=`[[!getContext]]` &resourceId=`4`]]

Snippet getContext

<?php
$contextKey = $modx->context->key; 
return $contextKey

With this approach I alsways get nothing back, i dont know why, i hope it will return ID od translated resource from context ;

1
you need to echo the $contextKey not return it. - Sean Kimball
@SeanKimball return is actually correct in a snippet; snippets are executed as php functions which in fact do expect a return. - Mark Hamstra

1 Answers

1
votes

I don't think you need the [[!getContext]] in the &contextKey property there, the following snippet call should work better:

[[BabelTranslation? &contextKey=`other-context` &resourceId=`4`]]

The reason for that is the &contextKey property is used to determine the context of the translated resource. In your case, that was trying to load a translation in the current context, for a resource that is also in the current context. As there is no translation there, it returns nothing.

By specifying a different context that actually has a translation instead of the original resource, it can properly look it up.