Questions tagged [craft3]
For use with questions relating to the Craft 3 version of Craft CMS, including the Beta and RC releases.
112
questions
16
votes
2
answers
5k
views
How to save Matrix data programmatically in Craft 3
How can you programmatically save an entry that has a Matrix field in Craft 3?
(Something like this gist for Craft 2)
4
votes
3
answers
1k
views
Get array of titles instead of whole collection of entries' attributes
I know that to get the entries I can do:
craft.entries.all()
but instead of getting the whole collection of entries, I would like to get an array of titles from those entries (or any other field).
...
4
votes
5
answers
7k
views
Craft 3 language switcher
Does anybody successfully implemented a language switch run Craft 3? Trying the Craft 2 variant slightly adjusted but still running into issues: Invalid site handle: nl
<ul>
{% set otherLocales ...
8
votes
5
answers
3k
views
How do you set a user's group on a registration form?
In a registration form with public signup possible, how do you set the user group for a particular form?
As a stop-gap I am attempting to use the following code:
function init()
{
craft()->on(...
2
votes
1
answer
958
views
How to get the previous or next two entries
I have an entry which needs to display the previous two entries, and the next two. I see in the docs there's a nextSiblingOf method. That does nothing in a channel, and in a structure it will only ...
14
votes
7
answers
41k
views
"Unknown package has no name defined" composer error on upgrade
Upgrading from Craft 3.4.20 running Composer 1.10.17 on PHP 7.2. Running ./craft update all returns the following error:
error: Unknown package has no name defined. [followed by JSON object related to ...
11
votes
1
answer
5k
views
{parent.uri}/{slug}
In Craft 2.x you have the option of setting the top-level entries URL format for a structure section separately from nested entries i.e. top-level/{slug} and {parent.uri}/{slug}
But in Craft 3 the ...
10
votes
3
answers
2k
views
Craft CLI RC1 Connectivity Issues with MAMP Pro
I've been trying to run the new Craft CLI for the last couple of versions without any success. I figured maybe since we weren't at RC1 yet that it wasn't fully working. After seeing Ryan's video about ...
8
votes
3
answers
3k
views
Craft 3 plugins - Logging in a separate *.log file
In Craft 2, it was possible to have your plugin log to a separate file. For example, it would record items to a myplugin.log file. You would simply be able to do it like this...
MyPlugin::log('Lorem ...
7
votes
2
answers
2k
views
How to setup assets in multi site where each site should have its own assets?
I have a setup with multi sites that are separate domains.
site-a.com
site-b.com
I would also like to have assets separate for each site, like so:
site-a.com/images/picture1.jpg
site-b.com/...
7
votes
3
answers
5k
views
Multi-site setup in Craft3
Hi guys are the any more detailed tutorials on how to setup a multi site on Craft3 BETA? I created two sites now, a Danish and English through the admin (Settings → Sites). The domain is the same but ...
4
votes
1
answer
805
views
Caching in Craft 3 causes out of memory when including grouped for loop
I have a problem with using {% cache %}in Craft 3, although the code runs fine without caching, and it works in Craft 2.
I have narrowed the problem down to the following code:
{% cache %}
{% set ...
4
votes
1
answer
3k
views
Basic ajax - how to?
I am new to Craft. I have done some ajax in the distant past. I have searched this forum and see lots of issues with ajax but it seems that there are a lot of different approaches. Craft docs have ...
3
votes
1
answer
581
views
500 Error with no details on site migration
I'm trying to migrate my site from a PHP5.6 host to a PHP 7 host in preparation for Craft 3.
I've copied everything across and am trying to load an exact copy of the production site on a different ...
3
votes
0
answers
649
views
Searching for Multiple Categories and Tags
I've been pulling my head for the past day on how to filter products with multiple categories.
After a long search, I found and implemented on my project, Advanced Search with tags and categories
It ...
2
votes
2
answers
555
views
Cleanup Craft Logs
Whenever I have PHP problems I'm looking into the Craft CMS logs. However, at first I noticed there's a ton of stuff getting logged which is useless for me. Under this amount of logs, I can't find ...
2
votes
1
answer
228
views
Missing Matrix row types on output after upgrade to Craft 3 (subsetting and cloning ElementQueries)
Update: Now I know the cause of my problem, I have appended to the original question title to try and help other people stumbling across the same issue.
I have a pending support ticket open with P&...
2
votes
1
answer
3k
views
How to saveElement in EVENT_AFTER_SAVE_ELEMENT without infinite loop
I am trying to update an entry's title in a Craft 3 module after an entry is saved. I cannot use EVENT_BEFORE_SAVE_ELEMENT because the title gets updated after this. If I use EVENT_AFTER_SAVE_ELEMENT ...
2
votes
1
answer
854
views
How can I set new user accounts to pending status in a Craft 3 module?
I have the following code in my site module:
Event::on(
User::class,
User::EVENT_BEFORE_SAVE,
function (ModelEvent $event) {
/** @var User $user */
$user = $event->...
1
vote
1
answer
3k
views
How to save a new entry with custom fields - Craft 3
I'm trying to create a new Entry via PHP, with custom fields (Craft 3). I can save it, however my custom fields don't appear. I've tried using setFieldValue, as well as $entry->excerpt = 'Lorem...';...
1
vote
1
answer
115
views
How to use multiple different instances Element API "Load More" button?
Following up on a previous question of mine:
How to skip the first few entries in a "load more" scenario with Element API?
I have a website that utilizes the "load More" (button) ...
1
vote
1
answer
1k
views
Craft 3: Error "variable now does not exist"
I upgraded a Craft 2 project to Craft 3 and am working on updating some template quirks. One I am having trouble with involves the following element query:
{% set scriptsAboutToExpire = craft.entries(...
10
votes
3
answers
7k
views
Plugin logging in Craft 3
How is logging handled in Craft 3? There's nothing mentioned in the docs at all.
None of the below exist.
Craft::log()
MyPlugin::log()
MyPlugin::$plugin->log()
I'm not seeing any logging in any of ...
8
votes
2
answers
3k
views
How to handle the SECURITY_KEY?
1) Where To Put It
I’m wondering how I should proceed with the SECURITY_KEY which is now mandatory in Craft 3 (RC2). It has to be the same for one project, right? So it should be shared across ...
7
votes
2
answers
3k
views
How do I upload an asset in Craft 3, via PHP
I've found various answers on how to upload assets via PHP for Craft 2, however nothing for Craft 3.
All answers use the method:
craft()->assets->insertFileByLocalPath()
E.g: How to upload an ...
6
votes
1
answer
2k
views
Running module migrations
I must be missing something or not understanding something.
I'm trying to build a module for an install, and I'd like to run the initial migration. So the module initial install migration for the DB ...
5
votes
2
answers
9k
views
Craft 3: how can I set dynamic Base URL in sites setting?
Sites localized versions are setup using Base URL like this:
— http://{baseUrl}/en/
— http://{baseUrl}/fr/
But {baseUrl} variables are not transformed using craft.app.sites.getAllSites().
{% set ...
5
votes
2
answers
2k
views
EVENT_AFTER_SAVE_ELEMENT triggered twice after saving an entry
I had this weird issue, not sure if that happens to you guys or not.
I'm trying to catch the 'after entry is saved' event, using the following code in my custom module's init() function (The module's ...
5
votes
1
answer
2k
views
Craft 3 Multi Category and Field Search
Looking for the solution to searching entries in one section that are related to multiple categories and match number field criteria. This is for a used auto website.
Categories:
Make/Model/Trim: ...
5
votes
1
answer
998
views
How can I install modules with Composer?
Installing a Craft 3 plugin via Composer is pretty simple. You require the package, update Composer, and install it via the CMS.
My circumstances require that our company use a private Module on all ...
4
votes
3
answers
720
views
How to rename filename of asset before (or after) upload in Craft 3
I want to change the filename before the file is stored, to prevent ugly, long and weird filenames uploaded by users.
I've found an example for Craft 2, but because of the changes for events I can't ...
4
votes
4
answers
2k
views
Is it possible to stop Craft from logging so much?
I've got a Craft CMS installation that is set to production mode. I notice that my logs get flooded with a bunch of entries which don't seem very useful.
For example, in a matter of several days, I'...
4
votes
1
answer
3k
views
Craft 3 - Save new Entry with Relations (Categories/Assets)
i simply can not get my "job" done. I try to create a plugin for Craft, a simple one. It reads some date and should create new entries out of this data. First i stuck on a stupid save-mistake, someone ...
4
votes
3
answers
1k
views
How do you save a new Entry to be enabled on 2+ Sites?
I've made a plugin that let's you import Entries from a CSV file and I'm working through adding localization (Sites) support to it, but I can't figure out the right way to enable an Entry for a second ...
4
votes
2
answers
4k
views
How do you set a flash message in the template in Craft 3?
How does one set a flash message in the templates? I can't find any documentation about this, only for plugins or getting the message.
My use-case is, I am checking if a user is allowed to access a ...
4
votes
1
answer
3k
views
Set up Craft 3 when the craft folder is above public_html on shared hosting
I'm trying to setup Craft 3 on a shared host. It succeeds when I place all files in the public directory and then go to /web.
But if I move the craft files to the folder /private_html/craft and the ...
4
votes
1
answer
1k
views
Craft 3 Multi-site with no "default" site
I have setup a Craft 3 multi-site with the following configuration:
But what I really want is:
Additionally, I want to have a 'default' http://localhost:8888 so I can always redirect to /en or /es ...
4
votes
1
answer
6k
views
Getting info on the currently logged in user
Trying to get the currently logged in user's groups. Trying to get at that by using the user ID. I am currently testing as Admin - user number 1.
Craft::$app->getUser()->id
Returns a user ID (...
3
votes
1
answer
1k
views
How to get section content from another site with multisite setting
I have a multisite on Craft 3 and I was wondering how to get section content from another site? Let's say I'm on a default site and I want to get contact content from site with handle siteA?
Can this ...
3
votes
2
answers
2k
views
Craft 3 multisite - are entries accessible between sites?
In multi-site is it possible to access entries between sites in the templates. Like a feed? ie. entry "a" on site "A" shows up in an index on site "B", and links back to the entry on site A, not a ...
3
votes
1
answer
318
views
Find entries from related section after certain date
Does anyone know how to achieve the following in Twig with Craft 3:
My sections
locations and trainings.
I want to find all the entries from locations which has a relation to trainings and a ...
3
votes
2
answers
4k
views
How to query an entry by a custom field in Craft 3
How do you query an Element by a custom field in Craft 3?
My first try, according to craftcms/docs was:
$country = Entry::find()
->section('countries')
->where(...
3
votes
2
answers
4k
views
How do I access current site handle in Craft 3 controllers
When my multisite is set up as @web/site, I cannot access the current site handle from my controllers.
Craft::$app->getSites()->currentSite->handle
I think this is because my form action ...
3
votes
2
answers
1k
views
Craft 3: Preventing Element from Saving in Plugin
I had a simple Password Confirmation validation function in Craft 2. In porting the function to Craft 3, I'm struggling to figure out how to handle the same thing. In Craft 2, all events were ...
3
votes
2
answers
112
views
Entry Tracker to see who has completed the course
I'm working on a project using Craft CMS for the first time, so far so good, however i'm stumped on how to do the following:
Create a button on each entry in a structure that states you have read the ...
3
votes
1
answer
938
views
What is the difference between the Translation Methods when creating a new site
I am creating a new multi-lingual site and the documentation does not explain the difference between the options in the translation method dropdown.
What is different for each of these and when is it ...
3
votes
1
answer
367
views
Updating matrix field from font-end with $entry->setFieldValue() pulls in Cp bundle on save
I have an entry with a matrix field which I'm updating from front-end. The update works fine, but when the (font-end) page reloads after submitting the form, the CP bundle assets get included (...
3
votes
1
answer
1k
views
Are there any alternatives to the deprecated Export plugin?
This thread Export Craft Data leads me to add a new question.
What is a good Craft 3 export plugin?
I know several for imports, for example the FeedMe plugin is doing a great job, but nothing to ...
2
votes
1
answer
1k
views
Understanding migrations and CLI commands
Can someone please help explain some basics regarding migrations and the associated CLI commands to help troubleshoot when things fail? Specifically,
How does craft know which migrations have been ...
2
votes
1
answer
238
views
\ns\prefix\Plugin::getInstance() returns null from another plugin in Craft 3
I'm building a plugin that extends the functionality of the Contact Form Tuner plugin and customize the email recipients based on different scenarios. The email addresses need to be managed in the ...