0

I have a LJ Dynamic field set up with the following code that pulls in a list of stores to an event section.

{% for store in craft.entries.section('stores').order('title') %}
  { "value":"{{ store.storeId }}" , "label":"{{ store.title | raw}}"}
  {% if not loop.last %},{% endif %}
{% endfor %}

My problem is that I can't seem to get the label from the field to display on the front end as I keep getting the error message "Impossible to access an attribute ("label") on a string variable ("412")" 412 is the value of the particular store I have selected for my event.

<p class="location"><strong>Where:</strong> {{ entry.stores.label }}</p>

If I add just { entry.stores } it will output the value.

This is probably something very obvious but got me a bit stuck.

2

The LJ Dynamic fieldtype only stores the value as a string, or as an array of values for the multiselect fieldtypes. The label in the settings is there just for displaying in the admin.

Either you could use the store.title instead of store.storeId as the value, if you only need the store name in your template. Or you could use the store id to get the data from the store in your template. Something like:

{% set store = craft.entries.section('stores').storeId(entry.stores).first() %}
{{ store.title }}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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