Reference a field name relatedTo(category) I'm building a site for a property developer that has multiple housing developments. And on each development page there is a siteplan image that shows a CGI of the all the houses on the development.

I'm trying to implement the Donkeytail plugin https://straightupcraft.com/craft-plugins/donkeytail-lite which lets you add pinpoints on images and have made some progress and have it working. However, every development page needs it's own siteplan, and so I have to create a field for each one.

So my question is how do I reference it in the template dynamically? As currently it is being called via variable.fieldname.topLeftStyles

But this only references the exact fieldname of one siteplan. So I need a dynamic way so that it can be different on each development page. 

{% set sitemap = craft.entries.section('sitePlan') %}
{% for variable in sitemap.relatedTo(category) %}
    &lt;span class="placeinphoto__dot" style="{{ variable.fieldname.topLeftStyles }}"&gt;{{ variable.title }}&lt;/span&gt;
{% endfor %}
Not sure I totally get your problem, but you can use bracket style notation to use variables for field handles, i.e.

{{ variable[someVariableHandle].topLeftStyles }}


or even something like

{{ variable[someVariableHandle][someVariableProperty] }}


As for actually outputting the fields in a sane manner, you'll need to map the variable field handles to your entries in some way – one way to do it is to simply use a naming convention for the field handles where you use some unique property on the entries (e.g. the entry ID) as part of the handle:

...
{% set fieldHandle = 'fieldname-'~entry.id' %}
{% if variable[fieldHandle] is defined %}
    {{ variable[fieldHandle].topLeftStyles }}
{% endif %}
...


Another way is to manually set up a map in your template – here's an example using entry IDs for keys, and the field handles for values:

{% set fieldHandles = {
    35: 'someFieldHandle',
    464: 'anotherFieldHandle'
} %}
...
{% for variable in sitemap.relatedTo(category) %}
    {% set fieldHandle = fieldHandles[variable.id] ?? null %}
    {% if fieldHandle and variable[fieldHandle] is defined %}
        &lt;span class="placeinphoto__dot" style="{{ variable[fieldHandle].topLeftStyles }}"&gt;{{ variable.title }}&lt;/span&gt;
    {% endif %}
{% endfor %}