Hot answers tagged

20

Rather than trying to store multiple stats together in a single block, another option would be to make a "Stat" (singular) block type, which only holds a single stat, and just have authors create as many of those as they need, positioned together. From your template, when looping through blocks, you can check to see if the current block is the first/last of ...


17

Folks may also want to checkin the Super Table plugin that just came out. It allows you to create table fields that include almost any field type: https://github.com/engram-design/SuperTable Keep in mind, though, that in many cases this may make your CMS/data pretty dependent on a plugin.


13

You can set a cookie from your template, which assigns visitors to specific groups: Craft 2: (Use the LJ Cookies plugin) {% set testGroup = craft.lj_cookies.get('group') %} {% if not testGroup %} {# New user - assign them to a group at random #} {% set testGroup = random(['a', 'b']) %} {% set expires = now|date_modify('+30 days').timestamp %} ...


11

You could also delete all rows in your craft_elements table, which have type set to Entry (or whatever ElementType you want to delete).


9

TL;DR: Let the content dictate how you model and architect it. If the site is sufficiently small or sufficiently simple, I think either approach is ok. My team has used both approaches, and it really depends on the Client's needs. An incomplete list of reasons to use separate channels and structures are: Tagging/Categorizing things like Products is ...


8

You can delete all of your existing entries and assets by executing this SQL query: DELETE FROM craft_elements WHERE type IN ('Entry', 'Category', 'Tag', 'Asset') All associated content, relationships, etc., will automatically be deleted. If you have a bunch of users you want to delete, you should at least spare your own admin account, so figure out your ...


7

The performance aspect is difficult to answer. On every pageload, Craft pulls all your global sets, which can be a performance hit, especially if you have many huge, complex global sets with a lot of fields. Any Single used in place of a global could be pulled on a need-to-use basis, i.e. not on every page, although the extra call to the EntriesService would ...


6

This question was asked prior to the release of the Neo plugin/field type. I think this would offer a better approach than the SuperTable (which was/is still awesome), just because I think it's easier to manage and template. I posted an answer to a similar question with examples here.


6

I'm not familiar with ACF, but if you're looking for blocks-within-blocks, you could use the Neo plugin/fieldType. It allows you to define blocks, and then have nested blocks. It allows for decent management of blocks, too, so that you have children of specific parents. For example: You could have the following blocks/content types: Copy Card Image ...


5

An alternate solution that might work is to create separate channels for 'stats' and 'quotes', and then use an entries field within your matrix block to add them to the 'stats' and 'quotes' blocks. Although not as accessible when creating the entry, it seems like it would potentially be a lot easier to manage all around, with no limitations on filedtypes, ...


5

This is a plugin I'm working on to do exactly what you are after. https://m.youtube.com/watch?v=n6ko2PKUqAo&feature=youtu.be The syntax to figure out how to create sections, elements etc is determined by reading through the craft service and model classes.


4

Structures simply add an extra bit of sorting and querying. You can look for entries in a structure the same way you look for entries in a channel. The difference is that you can also have parents and children in a structure with a manually set order. If you look at the section page for a structure and hover over an entry, you will see a move handle. You ...


4

I've determined what I think to be the best way to dynamically add Element's field content values to my responses. First off, the reason why field content values are being returned using $element->getContent() regardless of the Element relationship with the fields, is because the content table has field values as columns themselves. So when a Content ...


4

Two ways that this can be done is A) use a structure, or B) use custom routes. Using a Structure with different entry types defined for the various sub-page types would probably be the most straightforward and flexible. The base of the structure would be projects (but could just as easily start above projects, if you also wanted to use it to generate your ...


4

Your app can load up Craft using its bootstrap.php file: $craft = require 'path/to/craft/app/bootstrap.php'; That file returns a Craft\WebApp instance. From it, you can access all of Craft’s services, including the ElementsService which provides APIs for fetching elements and their content. Read through our Working with Elements guide to get an idea of ...


4

A huge boon to Craft is the ability to re-use fields across all your content – sections, categories, entry types or even users. The field groups are basically only there to make it easier for you to manage your fields in the CP, and impose no limits on where you can use any one field. Field re-use means that (at least with a little planning) the number of ...


4

MySQL has a hard coded limit of 4,096 columns per table, although that can be effectively limited by the data types of columns involved. Matrix fields get their own tables, so they don't count against the craft_content table. But yes... if you're planning on having non-Matrix fields in the 2,000 - 4,000 field range, then there's a chance you'll bump into ...


4

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 point. Let me know how you get on. Create an RSS feed, ensuring that the data you want to move is populating the feed. Here's a RSS template from the ...


4

"I'm just having a hard time figuring out what options there are." The options are virtually limitless. You can put almost anything you want into a safeUp method. Craft 3 is still in beta, and probably will be for another six months or so. They are likely to expand on the current docs for migrations, but I wouldn't expect to see that until much closer to ...


4

For now (when the docs are not ready) you look into the craft source how things are saved for example: https://github.com/craftcms/cms/blob/develop/src/controllers/FieldsController.php#L250 Based on the source code I've created the following migration file: https://gist.github.com/jeroenlammerts/de0471dc210749f4afe8d2e69bab46d8


3

There is no set maximum number of versions an entry can have, assuming you have unlimited database space. Take a look at the source code in the EntryRevisionsService for more information: https://github.com/craftcms/cms/tree/master-v2/src/services/EntryRevisionsService.php#L148


3

Okie doke. After bashing my head against the wall THIS is how you create your very own super deluxe content table. Allow me to explain... In your element class you will need to specify the following: public function hasContent() { return true; // You definitely will need this } public function hasTitles() { return true; // This is ...


3

I fixed it... I hadn't assigned a field to the section.


3

It sounds like you have 3 different general buckets of entries to consider: Streams of similar entries (News section, blogs, etc.) General content pages (100+ of them) Unique/one-off pages (Contact Us, application forms, etc.) Streams First, the easy ones: the streams of similar content (news, blogs, etc.) should each get their own Channel sections. A ...


3

I've written up an article with some basic examples of content migrations in Craft 3: https://medium.com/@mikethehud/craft-cms-3-content-migration-examples-3a377f6420c3 As others have stated I just read through the code base / api docs (https://docs.craftcms.com/api/v3/) to find out what methods and services to use to save specific things. Hope that helps!


2

I figured it out somewhat by using the Import plugin, by Bob Olde Hampsink, exporting all my slugs to a csv, then using the delete functionality of the plugin to remove all entries with a slug found in the csv. Worked perfectly!


2

Maybe this is not the best idea for your exact use case, but what about using a Structure section for your entries with two levels. Top level entries would be your "actual entries" and their child entries would be a substitute for your current matrix blocks. In the template of top level entries you then collect the content of the children in sort order, ...


2

This really is a case for nested Matrix fields. It’s something we definitely plan on adding at some point, but that won’t help you here. Looks like you’re using nested Structure entries to accomplish it right now – that’s probably your best bet for the time being.


2

I don't have much experience using tasks, but I often write plugin methods to move data around. Typically, I just use the EntriesService saveEntry or RelationService saveRelation as needed. Here is a sample from a recent data move: // Assign category and save entries foreach($unassignedEntries as $entry) { $success = craft()->relations-&...


2

That functionality doesn't currently exist out-of-the-box (as of 2.5.2752), but it would be possible as a custom development: You'd essentially need to create a clone of the Categories fieldtype, add your own config/setting to select the default categories, and then use the prepValue() method of the fieldtype to pre-select those default categories for new ...


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