Hot answers tagged

3

Try accessing the CP-Panel, in most cases this error occurs due to config files not being set correctly, thus not allowing craft to connect to the DB. If you get the installer page when accessing the CP-Pannel, that means it's most likely not able to access the DB with your current configs. Usually the URL would be my-host.com/backstage however this may ...


3

For what it's worth, it's coming in Craft 4. The author of the Reasons plugin has specifically said he won't port it to Craft 3, as this will be part of core in the next release.


3

You could use for example the dd() method with the craft3-dumper package. You can also use the debug toolbar. You could also use Sentry to get a nice overview about your errors with the craft sentry package. Or you could use xdebug. Or or or ... :) So there are severals ways to debug something.


2

These are probably coming from the incoming request in the $_SERVER PHP superglobal Yii2 does its best to figure out the incoming request, but that's relying on information coming from the client, which is insecure. Note the warning about potential cache poisoning in the Craft CMS docs: Don’t ever use the @web alias when defining your sites’ Base URLs. ...


2

This line: {% set hideMenu = craft.entries.section('mysection').showMainNavigation('not 1').one() %} will return the first entry that it can find in the section 'mysection' that has showMainNavigation off. So as soon as you disable it for one entry, hideMenu will 'return' true, whichever page you're on. So to fix this, if mainEntry is your current entry, ...


2

Following the Digital download docs you may need the file path, so in order to get the file path in Enupal Snapshot you may need to return the asset model of the PDF: {% set settings = { filename: 'my-first-pdf.pdf', inline: false, asModel: true } %} {% set assetModel = craft.enupalsnapshot.displayTemplate("reports/pdf-report", ...


2

Ok this was easy. Tried it at first but didn't work and was successful after another go. All it needed was a array of Entry IDs. Working code: $entry = Entry::find()->id($entryId)->one(); $entry->textField = 20; // works $entry->entriesField = [$relatedEntryId1, $relatedEntryId2]; // works Craft::$app->elements->saveElement($entry);


2

Here's how you would do that... Pass your parameter to the class: 'transformer' => new MyTransformerClassName($user), Use a constructor to save it as a property: class MyTransformerClassName extends TransformerAbstract { private $user; public function __construct($user) { $this->user = $user; } public function ...


2

_category can only be viewed if it's included in another file, because of the underscore. A twig file with an underscore cannot be loaded directly via the URL. You may also read What is with the underscore in twig template filenames? or hidden templates from the Craft Docu.


2

Per my earlier comment, the convert_encoding filter is causing this, I think only in newer versions of Twig than what my live site running Craft 2 uses. I guess that probably somewhere in my site content, one of our content managers somehow inserted a character that convert_encoding is choking on. Rather than figure out where that is, and know that the ...


2

The submit action is the actionInput input {{ actionInput('users/login') }}. This will call the login method of the src/controllers/UsersController and perform the action. You may also take a look at User Element & Events where you can listen on various user events like EVENT_BEFORE_VALIDATE, EVENT_BEFORE_AUTHENTICATE etc.


2

In Twig, you never want to use delimiters inside other delimiters (e.g. {{ ... {{ ... }} }}). Here's how you would format it instead: <h3>{{ wordBoldTitle | replace('#', '<strong class="font-weight-extra-bold">' ~ entry.title ~ '</strong>') | raw }}</h3> What we're doing here is using Twig concatenation (via the ~ operator) to ...


2

It turned out that MAMP Pro was stripping out the Authorization header, so every request was treated as a request to the public schema. The solution for MAMP Pro was to enable "Identical PHP version for all hosts (module mode)" in the PHP tab. Thanks to Brandon Kelly from the Craft forum for pointing me in the right direction.


1

Based on our discussion in the comments I'm very certain that the problem lies within the settings of the fields in your assets. In your Optimized Image Variants have you set the Image Format wrongly? If it's not that, then I'm still leaning towards some field/setting rather than the plugin acting wrongly as there were no errors/warnings logged containing ...


1

I really miss the Reasons plugin and am disappointed the makers of Craft didn't roll it in to Craft 3. Not quite what you're looking for, but you could try using the Control Panel CSS and Control Panel JS to add lightswitches that show/hide specific fields. You could start with the field hidden, and require a click on the lightswitch to show it. It's a bit ...


1

I think I did this successfully with help from another answer on here. I removed the data from the craft_elements table by using the fieldLayoutId column to identify the entry type I wanted to remove. Seems it removed the data from the other tables as well.


1

A compatibility issue. Running PostgreSQL12+ (PgSQL12+) couldn't finish Craft's installation setup. I have no idea what change in PgSQL12+ could cause this behavior but downgrading PgSQL12 to lower versions like PostgreSQL11 worked as expected. However Craft's docs states that PostgreSQL 9.5+ should meet Craft’s server requirements. I can't take this for ...


1

One way would be to use the positionedBefore query. Let's say Node 2 has the ID of 1000. Then you would write it like this {% set nodes = craft.navigation.nodes('main') .positionedBefore(1000) .all() %} The output would be all nodes before the node with the ID of 1000. In your case just Business Environment. With descendantOf you would get all ...


1

It sounds like something/someone is updating which could be causing the migrations to run and then subsequently fail... that could cause data loss but that's hard to say or know exactly. When this sort of thing happens, you should be reverting to a last known good backup and then figuring out what went wrong. That's going to be the only sane way to debug ...


1

If one single update query (on one record) is taking over 2 minutes, I would guess that the bottle neck is the database. You could check if this is an incident or if these update queries are structurally slow.


1

I would recommend running the Craft queue in a background process as detailed here. This way it won't bog down your control panel and can just chug away in the background.


1

Well, you can do: {# Get segment 2 from the URL #} {% set company = craft.app.request.getSegment(2) %} {# Get content where myCompanyField matches segment 2 #} {% set entries = craft.entries.section('mySection').myCompanyField(company).all() %} But I need to know more about the structure of your content.


1

What you are looking for is the relatedTo parameter (docs) and this post will also help. If you wanted to return any entries which has (any) tags attached, you could do: $entries = Entry::find()->tags(':notempty:')->all(); Where tags is the handle of your tags field.


1

I tried eager loading before, and I couldn't figure out how to do it. https://docs.craftcms.com/v3/dev/eager-loading-elements.html Now I just query it using SQL. I know it's a bit hacking, but it gets the job done. The DB structure of craft_content table hasn't change since Craft 2 (when I started using craft), so its unlikely that future updates will ...


1

I would first suggest getting your static HTML site up and running with twig, then slowly adding dynamic elements as you learn more about Craft. Start with two template files _layout.twig and index.twig. _layout.twig is the file that all pages will extend, so it will contain all your html meta, css, js, etc. Within the _layout.twig you can define areas that ...


1

It seems like the easiest way to address this issue is to remove the dependency from your composer.json file and to then run composer update


1

Solution Login to the server and access mysql and find your database. Select the fields table to locate the ID of the problem field. SELECT * FROM fields; Remove the field using the ID. DELETE from fields where id = '355';


1

I came across the same issue. So how i solved it is to modify the modules array like this and now the module is loading: return [ 'modules' => [ 'zip-assets-craft-3-module' => [ 'class' => \modules\zipassetscraft3module\ZipAssetsCraft3Module::class, ], ], 'bootstrap' => ['zip-assets-craft-3-module'], ];


1

Happened to me - a mixture of this and this helped me. Specifically I did the following (as I wasn't using project.yaml): Uninstall plugin via control panel Remove the plugin's table row from plugins table in database Remove any the-plugin-name_ prefixed tables from database Reinstall plugin Note: you will lose any plugin settings :( Still curious what ...


1

If you have a module instead of a plugin, make sure your new service is registered in the config/app.php Like so: return [ 'modules' => [ 'core-module' => [ 'class' => \modules\coremodule\CoreModule::class, 'components' => [ 'member' => [ 'class' => 'modules\...


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