13

You get this error because {{ block.slideLink }} returns an array of EntryModels (even if you set your Entries field up to only allow 1 entry). So you need to add the first() method to get the first (and only) EntryModel that you are interested in: {% set entry = block.slideLink.first() %} Access the url property to return the URL of that entry: {% if ...


8

Simply put, an Entries field is an array containing entry ids, and your form needs to send it that way. Just replace name="fields[tbdDesignerUrl]" with name="fields[tbdDesignerUrl][]". That way the value gets submitted as an array. Also replace value="{{ entry.designerUrl }}" with value="{{ entry.id }}", since we need the submitted value to be an entry id.


8

Craft has Hooks and Events which get invoked at different points in the core code. In your case the entries.onBeforeSaveEntry event would be perfect. Example: public function init() { parent::init(); //Event: onBeforeSaveEntry craft()->on('entries.onBeforeSaveEntry', function(Event $event) { //Is the entry in the section 'parts'?...


7

All related fields (assets, entries, categories, tags, etc) are designed to store more than one item, and thus always return an "array-like" object (although not technically an array), even if you have the limit set to 1. Thus you first need to either loop through the items or grab the first item using first or [0]. In addition, each item is an object model ...


6

The reason it wasn't rendering is because my original entry field is an Entries Field (see templating examples in the docs). The relationship fieldtypes (Entries, Assets, Users) require that you include the length filter in your conditional like so: {% if entry.fieldHandle |length %} {{ entry.fieldHandle}} {% else %} {{ global.fieldHandle}} {% endif %} ...


6

I got around this issue by looping through all fields that were of BaseElementFieldType re-setting them to their current value. $fields = $entry->getFieldLayout()->getFields(); $referentialFields = array(); foreach ($fields as $layoutField) { $field = $layoutField->getField(); if ($field->getFieldType() instanceof BaseElementFieldType) { ...


6

This is how relationships work in Craft at the moment. Each relation equals +1 query. If you don't access your relation on an entry the query isn't executed. So by only fetching title and/or id you don't run any extra relationship queries. Caching is your best option at the moment to make the query count go down. Make use of caching to cache large chunks of ...


6

See What is getContent() / the ContentModel, and how do I use it to get and set custom field values? So you needed to change the method used for setting content on an element. Also see In a plugin, how do I save an entry with a related entry So the relation fields always expect an array of ids, even if there is a single relation. Putting those together ...


5

Related entries in a matrix field are technically related to the matrix block and not the entry. So you will first want to get the related entries via relatedTo(block); then loop through the related entries to get the field values. {% for block in entry.menuLinks %} {% set relatedEntries = craft.entries.section('SectionName').relatedTo(block) %} {% ...


5

There's already a popular feature request for this: "Entry Type" setting for Entries fields But yes, it's currently also possible to do this by extending the default entries field type and adding your custom criteria with getInputSelectionCriteria(). class BusinessLogic_CustomEntriesFieldType extends EntriesFieldType { public function getName() { ...


4

I believe the code below should work. This code assumes you are on a single entry page or within a loop and your entry is available to you with the entry variable. You may need to adjust the block.type name and block.employees entries field name to match your proper handles. I've added comments inline to clarify each step: {# Loop through your Matrix Field #...


4

To do this, you would need to use getPrev() and getNext() on the related entries’ template. The trick is telling getPrev() and getNext() to use the order you defined in the source entry’s Entries field. So first, you will need to get that source entry. If you only have a single entry in your structure section that has one of these Entries fields, that ...


4

OK so here is my solution : 1/ define a custom permission for user groups public function registerUserPermissions() { return array( 'updateTopNews' => array('label' => Craft::t('Update Top News')), ); } 2/ simply add css to hide the field when user has not the permission in my plugin init function public function init () { ...


4

Try something like: {% set breadGroups = entry.breads | group('bread.first.id') %} {% for breadId, blocks in breadGroups %} {% set sum = 0 %} {% for block in blocks %} {% set sum = sum + block.quantity %} {% endfor %} Total qty for Bread ID {{ breadId }}: {{ sum }} {% endfor %} The group filter consumes a list — in ...


4

You're very close. Try this: $entry->getContent()->setAttribute('metaStatus', 'Declined'); craft()->entries->saveEntry($entry);


4

What you could do is get the ids of the featured element, and exclude those from the second craft.entries call. Something like this: {# Get the ids of the featured items you got above #} {% set featuredIds = featured.ids() %} {# Get entries in section 'blog' which don't have an id in featuredIds #} {% set allEntries = craft.entries.section('blog').id('and, ...


4

I was close. I was correct in assuming my syntax was incorrect for setting the value of an entries field. Since an entries field is an array of elements, not just a single element, I just needed to set the value of the field as an array instead of a string. Changing $cart->setContentFromPost(['entriesFieldHandle' => $entry->id]); to $cart->...


4

From your screenshot, it looks like you've added a Single section, which by definition, there will only be one "entry" in. Since there aren't any other types of sections, you don't have a "New Entry" button in the upper right of the entry index page. If you want to create sections that you can create multiple entries in, you'll need to create either a ...


4

It’s not totally clear from your question where you’re building the relation to the categories, but I have a feeling that this is the solution you’re looking for. {% set groupParam = '{ object.categoriesFieldHandle.first() ? object.categoriesFieldHandle.first().title : "No categories" }' %} {% for groupTitle, entriesInGroup in entry.entriesFieldHandle|group(...


4

It needs to be: {destination.first().slug} Or if this is for Craft 3: {destination.one().slug}


3

This should do it for you: $entry->$fieldHandle->last()->uri;


3

{% if '4' not in navigation.navi.ids() %} {% exit 404 %} {% endif %}


3

It's order('sortOrder') instead of fixedOrder(true). {% set entries = craft.entries({ relatedTo: { sourceElement: entry, field: 'entriesFieldHandle' }, order: 'sortOrder', limit: null }) %} If you don't make any further modifications to the params (i.e. reverse order, other limit) there's also the short syntax for the above that Jamie already ...


3

While you said that Attempt 1 was giving you the correct entries, just in the wrong order, if you have two blocks, you will probably find that you’re getting all blocks’ related entries each time. Because when you set that relatedTo param on block.entries, you’re actually overriding the existing relatedTo param that the Entries field type set, which limits ...


3

You guessed right, you have to set all already added entries again. To do this, just have some Twig logic when outputting the fields: {% for currentTeam in entry.tournamentTeams %} <input type="hidden" name="fields[tournamentTeams][]" value="{{ currentTeam.id }}"> {% endfor %} <input type="hidden" name="fields[tournamentTeams][]" value="{{ team....


3

I'm not completely sure of the technical reasons (I guess something to do with relation fields not have a column in the craft_content table), but you also need to re-save the existing ids for any relation fields (Assets, Entries, Categories, Matrix, etc) before the element can be saved: $entry->setContentFromPost(array( 'metaStatus' => 'Declined',...


3

You are using a dropdown field, so you can't query for the counties in use directly from the database. (This would be possible if you had chosen to use categories or tags for them.) But what you can do is to loop all your jobs entries to collect their respective counties. {% set entries = craft.entries.section('jobs').limit(null) %} {% set counties = [] %}...


3

It's a little tough to say, since you it seems like you haven't actually architected any of this in the Craft back-end yet. I encourage you to create a field (or fields) which would be a good container for this data. Once you've established what kind of field you're using, you may find that there is a different answer... but based on your current intent to ...


3

Response via Slack from Brandon Kelly: Accessing custom field values from PHP is the same as in Twig - once you have the UserModel it's just $user->myCustomFieldHandle or $user->myEntriesField->first(), etc. Managed to get via following: $user->company->first()->title


3

Dropdown fields (and other simple option-based fieldtypes such as Radio Buttons, Checkboxes and Multi Select) are pretty dumb. By design, whenever an Entry with a Dropdown field is saved, Craft simply grabs the selected value for that Dropdown field and stores it in the database for that Entry. Unlike relational fields such as Assets or Categories, there's ...


Only top voted, non community-wiki answers of a minimum length are eligible