Questions tagged [craft2]

Questions specific to the Craft 2 version of Craft CMS; avoid using for questions applicable to all or multiple versions.

Filter by
Sorted by
Tagged with
3
votes
1answer
1k views

Merging 2 Entries Array's

I have these to arrays that I need to merge into one array, but can't figure it out. Please advise {% set entries = craft.entries.section('publications').search('nonMembers:0') %} {% set entries = ...
3
votes
1answer
305 views

Impossible to invoke a method (“limit”) on an array

I recently upgraded a site from Craft 2 to Craft 3, so I'm trying to figure out what was deprecated and caused this error. At the top of the page I have this {% set solutions = craft.entries....
2
votes
1answer
89 views

Maintaining order when getting by entries by ID

I'd like to get a certain set of entries in a specific order, but the element query comes back ordered by the default 'postDate desc' {% set ids = ['4213','3200','4204','4212'] %} {% set ...
2
votes
1answer
74 views

How can I return only 1 random block in a Matrix in Craft using Twig?

I have a matrix with a couple of text fields for a caption, location and URL and an image Every time this page loads I want a random slide to show - so the background image is random, as well as the ...
2
votes
1answer
45 views

How to directly get value of text field in a given section of type structure?

I am trying to get a value of a text field that is in a Section which is a structure and has multiple entry types. I don't want to use a loop. I tried this and some other variations but does not give ...
2
votes
1answer
58 views

Update a lightswitch field in Craft CMS 2

How can I edit a lightswitch field in an entries field layout via PHP? This is my current approach public function actionSponsoredEntriesPriority() { $this->requireAdmin(); $this->...
2
votes
1answer
183 views

Is it possible to pass a variable to an event in a plugin?

I need to find out if any changes have been made to the entry on successful save. Using events entries.onBeforeSaveEntry and entries.onSaveEntry seems to be a way to do it. Maybe. Can I pass some ...
2
votes
1answer
30 views

ElementCriteriaModel combine with 'and' and 'or' filters

Saying I want to convert the following SQL query into ElementCriteriaModel: SELECT * FROM users WHERE fieldA = 1 AND (fieldB = 1 or fieldC = 1) I can't find a way in ElementCriteriaModel to do so. {...
2
votes
1answer
86 views

Set a route for all requests within a plugin

I’m trying to use a plugin to set up a site route that will direct every page request to a special template. This is what I’ve set up in my plugin file. public function registerSiteRoutes() { ...
2
votes
1answer
31 views

Craft 2 CMS - How to change Limits in Dashboard

I'm very new to Craft CMS. The company I work for, has their website build with Craft. The website was build by a 3rd party company, Now they gave me the responsibility to give the site a facelift. ...
2
votes
0answers
225 views

Order entries by custom date field

I want to modify this query so that the dated entries are sorted in descending order on a custom field called 'startDate'. Have tried adding .order('startDate') to the end of the craft.entries(query)....
2
votes
0answers
64 views

Can you make Craft 2 Stateless?

So we are moving to Google App Engine Flexible which means we cannot store sessions on files. So I wanted to know if anyone has been able to make Craft 2 Stateless and how was it accomplished? Thanks....
1
vote
1answer
55 views

Just upgraded to Craft 3, environmentVariables changed or stopped working

In my Craft 2 install, I had many links in Twig templates like this: <link rel="stylesheet" href="{{ craft.config.environmentVariables.baseUrl }}assets/css/styles.css"> I recently upgraded to ...
1
vote
1answer
48 views

How to create an entry with MySQL?

I'm trying to create a new entry from within the database. The section is defined in craft_sections, and the entries for craft_elements, and craft_entries seem correct after the script is run, but no ...
1
vote
2answers
66 views

Which twig file is being used and how?

I have a page in Craft (2.x) that displays several links and I was able to find which twig file had those links by searching the code base of twigs. Those links point to some Angular code with links ...
1
vote
1answer
46 views

How to have Craft 3 and 2 on same host?

I have a Craft 2 installation that I'm upgrading to Craft 3. I've got v3 running locally in its own virtual host, but now I need to temporarily put the dev v3 instance in the same hosting account as ...
1
vote
1answer
518 views

Ajax Post to Plugin Controller

I have been stuck on trying to make an ajax call to a custom plugin controller in Craft 2 for a few days after trying everything from following the documentation for Craft 2 as well as looking up ...
1
vote
1answer
130 views

Sending a custom email in the users prefered locale

Usecase: I'm sending out custom emails based on certain events to my users. These users have chosen a certain prefered locale in their profile settings and I'd like for those emails to be in that ...
1
vote
1answer
17 views

How to filter entries with null value in date field?

I have date field in entry that is empty therefore has null value. I'd like to filter entries that have date field value equal to null. How would I set that parameter on element criteria object? I don'...
1
vote
1answer
19 views

Hide flagged (inappropriate) comments from comment list

Craft CMS V2. Comment Plugin: verbb comment {% set comments = craft.comments.all({ limit: 10, status: 'approved' }) %} {% for comment in comments %} {{ comment.comment }} {% endfor %} ...
1
vote
1answer
145 views

Local DB SQL 'CDbException' Errors on Craft 2 site

Just tried to get a local site working again but getting all sorts of issues. I have updated the website online and downloaded the database, installed locally. I have also the craft/app folder to my ...
1
vote
1answer
73 views

Craft 2 Commerce 1 cart session expiry

Is it possible to change the cookie timeout just for the cart? E.g. I'd like to clear abandoned carts after X hours and keep all the other sessions untouched (e.g. user sessions etc). Please advise ...
1
vote
1answer
92 views

Pagination Slug Issue

I've setup a 'posts' section with a collection of posts. I'm trying to add pagination to the individual post entry. I've copied the pagination code from the Craft CMS documentation but I'm having ...
1
vote
1answer
77 views

Clear template cache after update sale on Craft Commerce

How can I clear products template cache after update sale ? Because product price don't change ... Thank you.
1
vote
1answer
220 views

CSRF token is null or empty in craft 2

I'm having an issue with Craft 2.6 and the CSRF token. I enabled Csrf Protection in my general.php file by adding this line $config['*'] array so it looks like: $config['*'] = [ ... '...
1
vote
1answer
448 views

Variable “entry” does not exist in template at Structure Section

So, the subject. I am currently working with customer of craftcms v2. I am setting up Structure Section where I want to add Entry Type for index listing of items and add some items in list. So, here ...
1
vote
1answer
89 views

Adding entry type using setContentFromPost

I'm creating a new user using $user->setContentFromPost(). It all works fine except I can't attach an entry to an Entries field. $user = new UserModel(); $user->username = $email; $user-...
1
vote
1answer
79 views

Custom plugin log not logging

I'm having this weird issue that both of my custom plugin logs are not working but all other third party ones including craft.log work fine. By 'not working' I mean the log file is generated, but ...
1
vote
1answer
86 views

Failed Stale Template Cache Delete Error…Analyzed…But No Answer

For some of the extremely static content on my site, I use caching to prevent multiple db queries during every single load. I also have multiple locale on my site with custom cache key names. The ...
1
vote
1answer
25 views

Craft Internal Server Error

I am getting the following error: Internal Server Error CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #34 of SELECT list is not in ...
1
vote
1answer
46 views

Implement hreflang with multi sites

I currently have multi site config. One site have 2 locales. My configuration like so: 'example.com' => array( 'siteUrl' => array( 'us_en' => 'https://www.example.com/', '...
1
vote
2answers
76 views

Craft CMS 2 Task progression

In Craft CMS 2, I've created a task for updating Craft Commerce products from an Excel file. Everything's working correctly except the UI progression bar. The progression bar in control panel stays at ...
1
vote
1answer
31 views

Craft 2: What would prevent most cached template chunks from showing up in the `templatecaches` table?

I am working on a Craft 2 site that is exhibiting some rather poor performance characteristics. On production, we use memcache for caching, and monitoring on the server shows disappointing cache hit ...
1
vote
1answer
31 views

Copy of Craft instance generates “An unknown error occurred” for login

I needed to create a second instance of a craft 2.0 instance and so I copied the current instance to a new instance. I followed the directions found here: https://craftcms.com/guides/duplicating-a-...
1
vote
1answer
51 views

Receiving duplicate Sprout Form submissions

We're seeing duplicate submissions. It's between 2 - 15 of the same submissions, usually 7. They come in irregularly over the next couple minutes after the first one. And only sometimes. They are all ...
1
vote
1answer
36 views

Steps for integrating an HTML design to a website page and managing its content from backend

I am a beginner to Craft CMS. I have an HTML design for Craft integration. I need to covert this to a live URL page on my website. Also, I need to manage its content from the backend. I think we need ...
1
vote
1answer
85 views

Central Craft CMS management for agencies

We have now more than 60 active website running on Craft CMS and have been able to keep our lives somewhat straightforward when it comes to the development side of things (eg. code repository access, ...
1
vote
1answer
67 views

'If/else' statement inside 'nav' tag

Craft CMS V2. Comment Plugin: verbb comment <ul> {% nav comment in comments %} {% if comment.isFlagged() == false %} <li> {% include '_forms/templates/...
1
vote
1answer
20 views

How can I add fields in the Sprout design your form?

I am using Craft CMS 2.7.3 and sprout forms 2.6.0 version. I have created a dropdown field in the craft cms -> fields. How can I fetch this field or render this field in the Sprout form design? Even ...
1
vote
1answer
49 views

Programatically add lines to a Super Table field

I am trying to add new lines into a SuperTable field of an entry from my plugin. Following the Developper sample, I am able to change set lines to this SuperTable field. But it is replacing the ...
1
vote
1answer
82 views

Looping Entries in Super Table, display row details

I have a Super Tables field, containing related entries: I'd like to display the field name (ie 'English Links') in a template, but can't figure out how, the following outputs a string of values and ...
1
vote
1answer
18 views

Importing fields into A&M Forms plugin

I'm currently using the A&M Forms plugin and was wondering if I can import fields from the native Craft 2 fields? I have already created 20 or so fields that I will use in both the native ...
1
vote
2answers
138 views

Send email with dedicated SMTP settings from a Craft 2 plugin

I have looked a lot for this but cannot find any dedicated solution. Basically I want to do this: How to send email from Craft 3 custom plugin? … but for a Craft 2 plugin. A how-to for the global ...
1
vote
1answer
26 views

bootstrap.php returns a value of 1 in Craft CMS

I have a Craft CMS instance that I created a copy of by tarring up the folder and then dumping the mysql database and then transferring that to a different server. On the target server I restored the ...
1
vote
1answer
61 views

Cannot access assets - unable to open image

I'm on Craft 2.7.8 and cannot access some of my assets - getting Unable to open image ../html/assets/xxx.jpg error all the time. I've checked the owner, group and permissions dozen of times, ...
1
vote
1answer
1k views

Return JSON array without extra square brackets

I'm having difficulties to remove an additional set of square brackets or avoid including them within array. My JavaScript code currently accesses array's object at 0 index and therefore I'd have to ...
1
vote
1answer
81 views

Missing 'Plugin Store' tab in admin panel

I'm using Craft 2.7.9 and can't access the Plugin Store page. I've searched for fixes here but didn't find anything helpful. I've tried to access it directly via http://localhost:8888/admin/plugin-...
1
vote
1answer
42 views

Changing some letters in entry's uri before save it

I need to replace some characters in my entry's URI because we have some letters which do not exist in English like "ş" or "ç". It is a problem for SEO and we have to change each time manually. I ...
1
vote
1answer
102 views

Get a specific product with Element API, Commerce and Craft 2

How do I get a specific product via Element API? Here's what i have so far 'api/product' => function() { $productId = craft()->request->getRequiredQuery( 'productId' ); return [ ...
1
vote
1answer
64 views

Craft 2.X Local setup error – Craft not connecting to MySQL (via Sequel Pro)

Novice dev here, really struggling to get my local setup functioning. After a couple of days of wrestling with Apache config settings, I finally have Craft connecting via a VHOST setup. The problem –  ...