How to use a dynamically defined field handle in a plugin? I'm trying to make a plugin more generally usable (so others could use it). For my own use, it uses a category field called 'mainCategory' but I'd like that the field handle could be specified in the plugin settings.

What I imagine is:

$url = $entry-&gt;mainCategory-&gt;last()-&gt;uri;


becomes:

$plugin = craft()-&gt;plugins-&gt;getPlugin('myPlugin');
$settings = $plugin-&gt;getSettings();
$fieldHandle = $settings-&gt;categoryFieldHandle;

$url = $entry-&gt;getField($fieldHandle)-&gt;last()-&gt;uri;


Any suggestions?
This should do it for you:

$entry-&gt;$fieldHandle-&gt;last()-&gt;uri;