Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [array]

The tag has no usage guidance.

1
vote
2answers
24 views

Syntax for Multisort Filter

I am trying to use the new multisort filter to sort an array in reverse order using a date key, but can't seem to figure out the correct syntax. Here is what I have: {% for rides in allRides|...
1
vote
0answers
22 views

Product variant association

On my Products details page I have 2 selects. The 1st select list out the Primary variants. Based on the selected Primary variant the 2nd select is auto-completed in with Secondary variants that have ...
1
vote
1answer
32 views

Element-API: Access the first url of an asset array

I have an asset field in my current project with the handle postImage, containing multiple image files. In my element-api endpoint, I wish to access the url of the first file only. I tried the ...
1
vote
1answer
129 views

Impossible to invoke a method (“limit”) on an array… but it's not an array?

I am receiving the error message "Impossible to invoke a method ("limit") on an array," but I don't think I am working with an array! Here is why I think that... First I set an albums variable: {% ...
2
votes
1answer
19 views

Build array from nodes from RSS where keys contain colons

Probably pure twig: I am building an array from nodes taken from a RSS-feed where one of the keys contains a colon which of course breaks everything. Like so: Node in feed: <media:thumbnail url=...
2
votes
1answer
29 views

Alphabetical index for a list of entries

I would like to build an alphabetical list of craft entries, but group them by the initials of one field of each entry. Thus, getting some kind of alphabetical index, like A Apples Ananas B Beer ...
1
vote
1answer
24 views

Pagination and Entry Model on Homepage

On my site I have some entries with images. In the entry template I paginate the images like so: {% paginate entry.images.limit(1) as images %} My homepage is a single random entry and I want to ...
2
votes
1answer
49 views

How to display entries filtered from more than one category

I want to try to learn how I can filter entries by multiple categories. I realise similar questions have been asked in the past, but all the answers are for specific use cases. All I want to do is ...
1
vote
2answers
526 views

How do I target the second item in an array with Twig?

I would like to select the second position in the array below. The problem is that this number is automatically changed. So I try to do this with .index function from Twig but I can not figure it out. ...
0
votes
1answer
454 views

Order twig array by date and time

I have a section called "events" in which I have a table field that contains dates and times of these events. So I want to order my events by date and within each day by time. I thought of mergin ...
1
vote
2answers
38 views

Using variable references to fields in a template

I have a situation where Matrix within Matrix would be ideal, but instead we've ended up with a Matrix row that has pairs of fields up to a maximum of 6: quote1 attribution1 … quoteN attributionN … ...
0
votes
0answers
19 views

Passing a variable through a hyperlink for a for loop on next page

I have a list of hyperlinks in a for loop generated by an array. order.html {% for vendorLink in vendorArray %} <a href="{{ siteUrl }}order/{{ vendorLink }}">{{ vendorLink }}</a> ...
1
vote
1answer
114 views

Argument #2 is not an array

Here we go: {% set state = craft.categories.group('locations').level(1).title(entry.title).one() %} {% set solution = craft.categories.group('institutionSolutions').title(entry.parent.title).one() %} ...
0
votes
0answers
29 views

Craft Element API data output as a hash instead of an array

I'm building and API feed using Element API plugin from Craft, and I'd like the data output to be serialized as a hash, but currently it's returning an array, as example bellow: <?php namespace ...
3
votes
2answers
167 views

How can I iterate through an array of field handles for an entry?

Background: One of my templates has up to 6 fields that should each go into the same markup. Here's an example with a courseDesign field: {% if entry.courseDesign|length %} <section class="col-...
2
votes
3answers
3k views

Overwrite value in object in array

I'm strangely having trouble with this simple Twig merge problem and can't find anything online. Simplified, let's say you had: {% set users = [ {name: 'Bill', age: 25}, {name: 'Tim', age: 30}...
1
vote
1answer
432 views

Returning an array to Twig from a plugin

I'am writing a plugin that has to return an array of data, however Twig does not seem to accept it if I return a PHP array. I don't want to use an explode in Twig to make it into an array. I have ...
0
votes
0answers
846 views

Dynamic variable in twig template

I am trying to set a dynamic variable name with a value in a twig template. Basically I am going through and counting an instance of an event that I want to show later in the template. I have tried ...
2
votes
1answer
140 views

Load entries based on category field value while multiple categories are selected

I have an activity calendar (more like a weekly schedule) which filters per day and per category. Because there are so many activities I can't just load them all in at once so I use some sort of Ajax ...
0
votes
0answers
91 views

Api Call => array => twig very slow!

I am grabbing some Data form an API and then I put quite a big JSON to an array. This array I am calling form my twig and I run a loop through every 34 keys. Now I am wondering why my site takes ...
1
vote
2answers
126 views

Recursive array search

I've got a plugin where I've written a simple recursive array search to find an array within a nested/multidimensional array which contains a certain value. private function arraySearch($haystack,$...
4
votes
1answer
72 views

Store categories in array by level in controller

I'm making a plugin and I need to get an array from a certain category group where the levels of the array are the same as the level of the categories in the group. So I used the following code to ...
1
vote
0answers
77 views

Create a baseball standings table

I am building a baseball standings table. I currently have a Single section setup in Craft to handle some basic info. It contains a table field with 3 rows: Team, Wins and Losses. I am able to output ...
2
votes
1answer
80 views

Remove duplicated entries from SuperTable related entries

Anyone able to assist me with removing duplicates in this example? So I have a related entries (cables) setup in a SuperTable. Some of these entries are duplicated across different rows. So a cable ...
1
vote
1answer
445 views

Iterate through all entries and count a specific value

I am having entries in a Craft channel-section. Each entry has the field "type" with one category filled. I need to iterate through the entries and count the amount of each category. Example: Entry ...
1
vote
1answer
307 views

How to replace a html entity within script tags using Craft replace

Apologies if this has been asked before, I can only find questions dealing with the reverse scenario (i.e. replacing special characters with html entities) I need to output special characters as part ...
1
vote
1answer
297 views

How to convert this 'array'

With FeedMe I'm importing some data and one of them I get is a complete array that is stored a plain text field. This array is a bunch of car options what I want to add in a table like this: {% set ...
0
votes
2answers
1k views

Create an Array in Twig and loop through fields in global set

So I've created a globals set (socialMedia) with 10 input fields, but this could grow in the future, for clients to add links to various social media accounts. This works fine except that the code for ...
1
vote
1answer
297 views

Call a Craft variable inside array

I'm currently trying to call variables called {{entry.title}}, {{entry.latitude}} and so on in an array. This is what it looks like: {% set markerArray = [] %} {% for entry in craft.entries.section('...
2
votes
2answers
116 views

Is it possible to convert plain text array to an unordered list?

I have a front end form with checkboxes which submits the data as an array into a plain text field in craft (named logGeneral_logInputIndications). Here's an example of what the content looks in the ...
2
votes
2answers
49 views

Can I exclude a commerce address by ID when retrieving a list of addresses?

I would like to retrieve a list of all commerce customer addresses except for one. When working with entries, this can be done with the {id: 'not ' ~ some.id } parameter. This doesn't seem to work ...
2
votes
1answer
1k views

Possible to merge and sum the values of an array?

I have a super table that has 4 columns. I'm trying to create an array based off one column (contentType) and merges to get only the unique values while taking the sum of a different column (points). ...
2
votes
2answers
1k views

Random Number from range

What is the best way to get a random number within a certain range? I made something but I guess there is a better way: In this example I want to position some elements randomly. This approach works,...
2
votes
1answer
75 views

Adding a random entry to an array

I have a navi on which one entry consists of a random channel entry from one section among standard singles: Single 1 Single 2 Random Channel entry Single 3 I thought about something like this: {% ...
2
votes
1answer
93 views

Insert entry into article field (elementselect?) on a user, with the “onBeforeSaveEntry” hook

I'm having a hard time inserting new content into an elementselect field for a user. Here's the code I'm working on so far, inside a custom plugin init() parent::init(); craft()->on('entries....
1
vote
1answer
87 views

How do I sort and display event entries when each event can have multiple start times?

I have two different event types in my Events channel. The first one is events and it is very straightforward: Title, Description, Date. The other one is films and it is a little more complex: Title, ...
1
vote
1answer
353 views

Pass a nested array to the params argument inside Craft's url() function

I have a list of checkboxes in a GET form which results in a URL with a querystring like ?q=&cat=&city%5B%5D=28&city%5B%5D=26&sort=asc&order=name when submitted. The Object/Array ...
2
votes
1answer
112 views

Query two sections filtered by different custom fields, then order them

Two channels: 1) exhibitions, which have a startDate and EndDate 2) events, which have a date I need to grab the current exhibitions, future exhibitions and future events, which I do using this: {% ...
4
votes
1answer
14k views

Is there a way to check if a value exists in an array in twig?

Done some searching on this but can't quite find what I'm looking for. Most threads are regarding keys. I want to know if there is a way to test if a value exists in a twig array. It should be able ...
3
votes
1answer
540 views

Eager-load and pagination

I'm currently working on a relation-heavy website with a colleague of mine and, for that reason, eager-loading stuff looks very appealing to us. We've succeeded in eager-loading pretty much everything ...
3
votes
1answer
1k views

Create an object of objects with merge

I'm trying to create an object of objects, can anyone suggest why object would only contain the last iteration of "itemObject"? {% set object = {} %} {% for entry in craft.entries.section("...
3
votes
1answer
585 views

Empty .getParam() does not return an array with dump()

craft.request.getQuery() returns: array (size=5) 'tags' => string 'anxiety' (length=7) 'maxPrice' => string '' (length=0) 'sessions' => array (size=4) 0 => string 'email' ...
2
votes
1answer
978 views

Conditional to detect mobile devices with getUserAgent?

I want to create a User Agent check. (Yes I know. It is evil.) So I created an Array. The whole idea is to see if the user agent contains a specific word. This way I hope to circumvent regex trickery....
1
vote
0answers
352 views

Advanced filtered search: Matrix fields and arrays

Having scoured the forums for similar questions of which there are a few, I'm still struggling to figure out my specific usecase. I have 4 filters and a search box (which searches a custom tag field) ...
1
vote
1answer
862 views

Apply 'random' to an array

How do I output one random line of an array? {% set img = [ { bildli: 'http://i.giphy.com/I0xDz0htjsiME.gif' }, { bildli: 'https://i.giphy.com/fA3JALhIi5YVa.gif' } ] %} {% for item in img %} ...
1
vote
2answers
367 views

Sorting multi-dimensional grouped arrays

My problem is that I don't know/understand how to sort complex arrays. I have a multi dimensional array of users from an external API. So it's not an array that I fetch from the Craft database. Let's ...
1
vote
1answer
346 views

Correct way to merge craft.user field arrays and use outside the loop?

I'm using preparse field plugin to limit the amount of tags a user can add to his account. I've modified the code slightly so the tags are processed as a comma, separated, list. The plan is to ...
1
vote
2answers
223 views

Can you lookup the value in a key-value array with the value in an entry field?

This might be impossible, but can you lookup a value in a key-value array with the value in a craft entry field? And perform math with it in twig? I'm trying to simplify my template code. I have a ...
1
vote
1answer
165 views

Add several feeds into an array

I'm relatively new to Twig and PHP in general, so please don't shoot me just yet for asking stupid questions! Basically, I've got several feeds from RSS to Facebook and Twitter. And I need to merge ...
1
vote
1answer
620 views

Output getSegments() array in template

Is it possible to output a getSegments() array in a template to then run conditions on? I can output one segment fine using getSegment(), but if I try to select one or more segments using getSegments(...