Miomir Dancevic
Miomir Dancevic

Reputation: 6852

MODx BabelTranslation return resources id?

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 ;

Upvotes: 0

Views: 523

Answers (1)

Mark Hamstra
Mark Hamstra

Reputation: 722

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.

Upvotes: 1

Related Questions