Hot answers tagged

24

Field groups are not specific to a particular channel or channel entry. They are just an arbitrary organization within the control panel for ease of use. What you would be looking for are the fields defined for the particular field layout for that entry. I.e.: {# loop through the fields in the entries fieldLayout Model #} {% for fieldLayoutField in entry....


16

I did this recently with my Ad Wizard plugin... There are several different parts which need to be brought together to make it work: In your Record file, add this to defineRelations: 'asset' => array(static::BELONGS_TO, 'AssetFileRecord') In your Model file, add this to defineAttributes: 'assetId' => AttributeType::Number Whichever template is ...


13

I believe you need to set the on value of your lightswitch field. on: (settings.mailerShowInfo is defined) ? settings.mailerShowInfo : "" So, the full settings of your twig code would be: {{ forms.lightswitchField({ label: "Show info in sidebar?"|t, id: 'mailerShowInfo', name: 'mailerShowInfo', value: settings....


10

You can get info about your fields using craft.fields.getFieldByHandle(). That will include a settings property, which will be an array of the field type’s settings. The actual settings available will differ depending on the field type, but Dropdown, Checkboxes, and Multi-select fields all have the same one: options. So in each of their cases, here’s how ...


10

The not so elegant way to do this is to re-use the field somewhere else, where you do have access to (e.g. a global set). But you probably want to avoid this, right? What you can do instead is to access the field directly using craft.fields. This function returns the FieldModel of your field, containing all of its properties. The FieldModel property you ...


9

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 types. For example, I needed to add 3 additional formats: 'extraAllowedFileExtensions' => 'bim, dwg, rvt' See the documentation here for details.


9

The feature request for this has been very popular since day one, so hopefully it's something P&T adds to the core some day. For the interim I just published a small plugin called Reasons, which will add simple field/value based conditionals to entry type field layouts - pretty much exactly like the OP describes it. Download from GitHub: https://github....


8

I always write migrations to do this. Here's and example for changing the label of a field. You could, of course, do whatever you want - modify fieldlayouts, add/modify/remove fields, etc. UPDATE Nowadays I use the Schematic Plugin to transfer all kinds of settings (fields, fieldlayouts, settings etc.) over different setups.


8

Twig has a "is defined" test that you can apply to a variable to see if it exists: {% if entry.possibleField is defined %} Yup! {% else %} Nope! {% endif %} And here is more information on using is defined.


8

If there was no default set beforehand, then your previous elements will have a value of null for that field. You should be able to include those in your "on" queries by querying for that null value as well as the "on" value in your templates: {% set onEntries = craft.entries.yourLightswitch([null, '1']).find %} This won't actually change the value of your ...


7

I can't answer your question directly as I never got even close to 300 fields yet. But even with 50 fields I had some serious slowdowns, especially when getting related entries in form of assets and such. I think you should definitely consider using the built in cache function to get good performance. In regards to that field name / instructions problem ...


7

According to the Craft docs , the table field returns an array of rows. Assuming that is the case, you should be able to use the Twig slice filter: {% for row in registration.registrationCost | slice(0, 3) %} You can then use a simple conditional to output the row divider: {% if loop.index == 3 %} <hr> {% endif %} Stephen


7

I eventually figured this out. Here's the code that's working for me: $newFields = array( 0 => '12', // $field->fieldId 1 => '15' // $field->fieldId ); // First we get all sections and loop through them $allSections = craft()->sections->getAllSections(); foreach ($allSections as $section) { // Then we get all EntryTypes of each ...


7

If your Redactor config included an "html" value in the "buttons" array, you can remove that, and add a "source" value to the "plugins" array instead. https://craftcms.com/help/redactor-ii-configs


6

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/Import options with a good UI for selecting which field you want to export.


6

The reason it wasn't rendering is because my original entry field is an Entries Field (see templating examples in the docs). The relationship fieldtypes (Entries, Assets, Users) require that you include the length filter in your conditional like so: {% if entry.fieldHandle |length %} {{ entry.fieldHandle}} {% else %} {{ global.fieldHandle}} {% endif %} ...


6

This would be a good task for a plugin. You'd essentially need to build the plugin to do a couple of things: (1) Use PHP in a service to list the contents of a directory. Once you have that list, you'd then need to... (2) Deliver that information to the front end via a custom field type. You can then use your new custom field type wherever you'd like.


6

You could output the categories in a way that makes them look like they are from a specific category when they don't have any categories assigned to them. When you're outputting any of the entries, just add a custom link if there isn't a category assigned: {% if entry.categories|length %} {% for category in entry.categories %} <a href="/blog/...


6

You can get the fields that aren’t in use anywhere by running this SQL query: SELECT f.* FROM craft_fields f LEFT JOIN craft_fieldlayoutfields l ON l.fieldId = f.id WHERE l.id IS NULL The easiest way to delete them would be from the Control Panel, but if you really want to limit your work to the database, you would need to delete those fields’ rows in ...


6

You can get your entry's parent entry with getParent(). Use this entry method in a conditional, if your entry has no hero image set. You can nest the code to climb up all of your structure's levels: {# Check if entry has hero image #} {% if entry.hero.first() %} {{ entry.hero.first().url }} {% else %} {# Check the parent entry #} {% if entry....


6

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, Asset, etc) can access any field. CON: This means that every element carries the weight of every field. Though if those fields are all empty, the performance ...


6

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'll notice that if you don't provide a namespace variable to the include, it'll use fields. {% if element is not defined %}{% set element = null %}{% endif %} {%...


5

try using this: https://github.com/lukeholder/dir to populate this plugin with the template names: https://github.com/lewisjenkins/craft-lj-dynamicfields/


5

Not with the out-of-the-box field types. You could create a field type that is category+default. The Default Color plugin might be a good place to start.


5

Currently, no. The list you see there is the result of a function in IOHelper called getFileKinds. It just hands out an array of options. While I don't have a recommendation for making this work, I do suggest you send a feature request to: support@buildwithcraft.com With it already being a function, I can see there being a possibility of them allowing users ...


5

Here's your problem... You're redefining entry halfway down the page. This page clearly uses the section's built-in routing functionality. I can tell because you use entry.body near the top of your page without explicitly declaring the value of entry. However, you later on use {% set entry %} to reassign the value of entry. Based on the new value of entry, ...


5

Another way to do this would be to assemble a list of the entry IDs that you want to look for a hero image in, in order, and then finding the first hero image related to one of those entries. To create that list of entry IDs, we start by creating an array of the current entry’s ID, and merge it with an array of the entry’s ancestors’ IDs in reverse order: {...


5

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, but it seems the most apt place to put my solution to this issue and contribute to more code samples. After some experimenting, I got a solution that works (...


5

As aberkie pointed out, Craft does use them internally, but they should not be left blank or you'll potentially run into some issues now and you'll miss out on some upcoming features. You can programmatically create one with StringHelper::UUID or use a site like guidgen.com to get a valid one.


5

Not sure what you want to do with the fields, but you can access them through fieldLayout. {% for block in entry.myMatrixField %} {% for field in block.getFieldLayout().getFields() %} {# get properties #} {{ field.getField().name }} {{ field.getField().handle }} {{ field.getField().id }} {# get value #} ...


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