Skip to main content
13 votes

How to add more options to the 'Restrict allowed file types' settings?

You can now set allowedFileExtensions and extraAllowedFileExtensions in your config file. The first will re-define the list of allowed files, where the latter will allow you to add additional file ...
Alexander Holsgrove's user avatar
6 votes
Accepted

How is Craft able to reuse fields in different Sections? (As opposed to EE.)

In Craft, all fields are stored in the craft_content table. They are otherwise independent of any field groups, layouts, sections, or anything else. PRO: This means that any element (Entry, Category, ...
Lindsey D's user avatar
  • 24k
6 votes

Programatically Adding Fields to a Layout

While I am adding them from a plugin, I ran into a similar issue as you, and like you, I didn't like the "recreate the layout from scratch" method the linked answer used. I know this question is old, ...
Shauna's user avatar
  • 181
6 votes

Exporting/Importing Fields

Check out https://github.com/engram-design/FieldManager I was looking for a way to duplicate a matrix field to make another variant. This works perfectly for cloning fields and seems to have Export/...
jsun's user avatar
  • 113
6 votes
Accepted

How does Craft automatically wrap `fields[]` around name attributes?

I believe its the namespace twig template function - and fields typically use the default namespace as fields. This is defined under templates/_includes/fields.html Looking at that file (below), you'...
crawf's user avatar
  • 3,552
6 votes
Accepted

Loop through fields of a matrix block

Check if the matrixField is populated: {% if entry.matrixField|length %}{% endif %} There are two options to pull out fields from a block type. Option A: use a for-loop pointed at your Matrix field ...
Dominik Krulak's user avatar
5 votes

I am unable to correctly return the url of an uploaded asset

I found the answer in a similar post here: Image asset url is not being output My problem was with my Asset Source settings. Now that I think about it, it's obvious: I had no public URL declared for ...
Steven Thate's user avatar
5 votes
Accepted

How can I get the type of a field using Twig?

You can use the className function {% switch className(field) %} {% case 'craft\\fields\\PlainText' %} {% case 'craft\\fields\\Dropdown' %}
Robin Schambach's user avatar
5 votes
Accepted

How to get column name of an entrie's field

It's actually OK to hard code the complete field column name (i.e. field_nationality_gkpaccfs) – it won't change between environments, or if the field is resaved (unless you change the handle, of ...
Mats Mikkel Rummelhoff's user avatar
4 votes
Accepted

Use Matrix field to output specific html

In your code block.type is the matrix block type, ie homeSlider. There's alot going on in your code that I'm not sure is intended or not, but let's say you had the fields mainImage and imageText as ...
André Elvan's user avatar
  • 7,288
4 votes

Migrate contents between fields?

I've managed to achieve something which works in the least technical way I can think of. Other solutions might involve migrating data directly within the database, but I figure this is a good starting ...
Matt P's user avatar
  • 1,538
4 votes
Accepted

Get field that contains search query

This currently isn't possible natively in Craft, but if you think it should be, you can create a feature request!
Brad Bell's user avatar
  • 67.5k
4 votes
Accepted

Control panel field name & instructions translations

If your main language site is dutch for example, you can do that using your own php files locale and naming them according the other locales languages, en.php, fr.php and put those files in craft/...
Barbara Cinotti's user avatar
4 votes
Accepted

Table fields, default single empty row, and never returning as empty?

You could test if the first cell is empty {% if entry.whiskeyTableHandle|length and entry.whiskeyTableHandle[0][0] %} {% endif %} Or you simply remove all default rows in the field’s settings.
carlcs's user avatar
  • 36.2k
4 votes

How to approach a multi-level floorplan

I'd use a Matrix field with a block for each floor. Adding a block provides fields for an Asset for the floorplan and a text box for the dimensions. The dropdown is purely javascript based, and I'd ...
darylknight's user avatar
  • 3,290
4 votes

How to add custom fields for products in Craft Commerce and output them in the cart

Ok, I think your thinking on this stuff is a little wrong at the moment. The way Commerce works is that when you add to a cart, it creates a lineItem. That data model holds basic stuff like qty ...
Jeremy Daalder's user avatar
4 votes
Accepted

How to get a list item <li> using a plain text field every time I hit enter

You'll want to split on the line breaks, then loop through the resulting array... {% for ingredient in listOfIngredients|trim|split('\n') %} <li>{{ ingredient }}</li> {% endfor %}
Lindsey D's user avatar
  • 24k
4 votes

Is it possible to use an existing field into a matrix?

You can use the neo Plugin or you can copy and paste the field settings manually from one field to your matrix field in your database interface. In your craft_fields table there is a column settings ...
Robin Schambach's user avatar
4 votes
Accepted

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

I figured it out! I ditched the macro and just included the following in my template: {% for field in courseFields %} <section class="col-xl mb-3"> <h2 id="{{ field.handle }}">{{ ...
Katie Fritz's user avatar
4 votes

User registration form with checkbox field

Just in case anyone else has this issue i got it working with these modifications. I think the hidden field was required for the possibility of null values. <input type="hidden" name="fields[...
Matt B's user avatar
  • 73
4 votes
Accepted

Element query: find entries where a field's value is greater than, or less than another field's value?

I agree that any solution where you run a query and then conditionally render the result isn't very efficient. You can do this in SQL by using the where() condition. craft.entries .section('...
Matt Banner's user avatar
3 votes

How to programmatically add fields to matrix blocks?

I'm assuming that you're attempting to create the Matrix, with one or more blocks each containing one or more fields, from scratch? I.e. you're not simply trying to populate content into an already ...
Fuglsetrampen's user avatar
3 votes
Accepted

Flexible content requirements for Matrix

If these Matrix fields are going to have a lot of fields then I'd recommend taking a look Pimp my Matrix to keep them well organised. If you're wanting to make your Tables more powerful and have ...
Jamie Jenkins's user avatar
3 votes
Accepted

Using the Search Filter with Entry Fields

{% set range = entry.model %} {% set categories = craft.categories.slug('not preferential') %} {% set entries = craft.entries.section('offers').search('title:' ~ range).relatedTo(categories) %} If ...
mcclaskiem's user avatar
3 votes

Upload Image Custom Field

I believe you are looking for the Assets Field
Ben Parizek's user avatar
  • 13.4k
3 votes
Accepted

Trying to capture categories field type data in user profile save/update

Usually, its very easy to pull data from a relational fieldtype (Categories, Entries, Assets etc). E.g. if your Categories field handle is memberGroups, you can simply do this: $categories = $user-&...
Mats Mikkel Rummelhoff's user avatar
3 votes

Disable or hide an entry field in the CMS

I wrote a plugin called Incognito Field, which is basically a plain ol' PlainText field that can be set to disabled, readonly or hidden. Perfect when you need to update a field via a plugin and never ...
Mats Mikkel Rummelhoff's user avatar
3 votes

Restricting access to fields based on user group

You can use the Control Panel User Group plugin to automatically add special classes to the <body> tag in the CP. Once those classes are in place, it's easy to use CSS or JavaScript to hide ...
Lindsey D's user avatar
  • 24k
3 votes

Defining fields on a per-entry basis?

Let's start by saying what you don't want to do... Don't use Matrix blocks to solve this problem. As you mentioned, the Matrix field would get pretty crazy, and you couldn't prevent people from using ...
Lindsey D's user avatar
  • 24k
3 votes
Accepted

How can I loop through a field and print each value individually?

Variable "entry" does not exist This error is being caused by the first line of your code: ... in entry.isotope %} You are either using this template code on an element that isn't an entry or haven'...
Jamie Wade's user avatar
  • 3,644

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