So I have a plugin with a service. Part of the service function is to grab a field (body) from an entry object that has been passed into the function.

namespace Craft;

class MyPlugin_ExampleService extends BaseApplicationComponent {

    public function example($entry) {
        return $entry->body;


The function will be called via Twig.

{{ craft.myPlugin.example(entry) }}

How do I go about getting the field data for the users current locale?

1 Answer 1


You're pretty close... You'll need to do this in a Variable, not a Service.

If your method already exists in a Service, or if you'll need to access it via PHP as well, then you can keep it in the Service. In that case, you'll still need a Variable method, but it can simply be a wrapper for your existing Service method.

  • I realized after posting this that your question is focused on locales. In theory, it should already be grabbing the value per the user's locale... is it not doing that?
    – Lindsey D
    Commented Feb 5, 2017 at 5:25
  • Thanks Lindsey. Sorry, I should have been a little more detailed in my question. Yes, I've passed the function through a 'variable'. It's grabbing the locale version of the content I'm struggling with. I can't find anything that simply gets the content as per the current locale... and it's not doing it automatically. Commented Feb 5, 2017 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.