Skip to main content
10 votes

Can I change which 'Format' options are available in my Rich Text field?

You certainly can using the Redactor Formatting config. Locate the config file for the Redactor setting you want to edit in craft/config/redactor and add this line: "formatting": ["h1", "h2", "h3"], ...
Jamie Wade's user avatar
  • 3,644
9 votes
Accepted

HTML Purifier Config File

Something like this in a .json file should work: { "HTML.SafeIframe": true, "URI.SafeIframeRegexp": "%^(https?:)?//(www\\.youtube(?:-nocookie)?\\.com/embed/)%", &...
Brad Bell's user avatar
  • 67.5k
8 votes

Can I change which 'Format' options are available in my Rich Text field?

What I like to do is to override the default options of the Format dropdown by setting "formatting" to null and adding my own list of options using "formattingAdd". This allows you to come up with ...
carlcs's user avatar
  • 36.3k
7 votes

HTML/View Source button not working/showing in WYSIWYG Craft 2.5 / Redactor II 1.1.0

You need to add "html" in the buttons array, and not "source" in the plugins array.
Andrew Terry Loveday's user avatar
5 votes
Accepted

Get Assets in JSON with ElementAPI

Something like the following should work: // elementapi.php return [ 'endpoints' => [ 'assets.json' => [ 'paginate' => false, 'elementType' => ...
Mats Mikkel Rummelhoff's user avatar
5 votes
Accepted

Passing JSON to Twig

The answer is to create a custom plugin that will read the json files from the folders in the public directory, parse the json, and pull them into the template. An alternative solution is to use ...
Sam Hernandez's user avatar
5 votes
Accepted

Removing P tag's in rich text area's

Seems like a simple striptags filter would do nicely in this case: <h1>{{ entry.titleField|striptags('<strong><em><br>')|raw }}</h1> If you're having issues with ...
Mats Mikkel Rummelhoff's user avatar
3 votes

How to skip the first X entries using ElementAPI

It seems that offset doesn't work when pagination is set to true (which is its default value). If you don't need pagination for your results, you can add your offset in criteria and set pagination ...
missmatsuko's user avatar
3 votes

Access Element API JSON in another environment

Brandon answered this in a github issue https://github.com/pixelandtonic/ElementAPI/issues/4 You can do that by setting your endpoint config to an anonymous function: 'my/endpoint/pattern' => ...
Spoeken's user avatar
  • 327
3 votes
Accepted

Feed Me: How to format JSON for a table field?

You can do this a number of ways, and essentially just need an array-like structure to represent the rows. "Table": [ { "one": "Option1", "two": "Option2" }, { "one": "Option3", ...
crawf's user avatar
  • 3,562
3 votes
Accepted

Feed Me: Importing a relationship between elements

Have you set the type of data you're providing for the category field? Each element field allows you to state what attribute the data you're trying to import. Title, ID or slug, which are shown in a ...
crawf's user avatar
  • 3,562
3 votes

HTML Purifier Config File

Following from Brad's answer (I'm not able to comment) I had to escape the backslashes to avoid JSON decode error. Version for Youtube and Vimeo { "HTML.SafeIframe": true, "URI....
sanscheese's user avatar
3 votes
Accepted

How do I add meta data and a page title through ajax?

You almost certainly don't have to update the meta tags when you use AJAX to load pages like this. Meta tags are not exposed to the end user; they're there for search engine crawlers and social media ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

Element API: Remove additional set of square brackets from JSON-String

Though I don't know the Element API, have you tried return $allOverChallenges; instead of return [ $allOverChallenges ]; It looks like you are simply adding these brackets (...
Matthias Redl-Mann's user avatar
3 votes
Accepted

Redactor can't add image into toolbar

You probably don't have an Asset Volume defined yet. The button won't show up if there are no Asset Volumes, regardless of what your Redactor config specifies. To add an Asset Volume, visit the ...
Brad Bell's user avatar
  • 67.5k
3 votes
Accepted

Image transforms not working properly

If I remember correctly, you will see urls similar to this http:\/\/mysite.dev\/cpresources\/404?x=CjvOQxsnA if you have generateTransformsBeforePageLoad as false. It could genuinely be the case that ...
joep's user avatar
  • 610
3 votes
Accepted

Loop through JSON object in Twig from the database

You'll simply need to decode the JSON string. Unfortunately, Twig doesn't ship with a json_decode filter, but there's a plugin. Here's how you'd use it: <ul> {% for block in entry.gridcontrol|...
Mats Mikkel Rummelhoff's user avatar
3 votes

ElementAPI - Can I use javascript/ajax to load json

You better use GET rather than POST : $(function () { var data = { 'CSRF': $('input[name="CRAFT_CSRF_TOKEN"]').val(), }; $.ajax({ 'type': 'get', 'contentType': '...
benoit_mire's user avatar
3 votes

ElementAPI - Can I use javascript/ajax to load json

Totally do-able. Once you have the ElementAPI plugin downloaded and installed, you'll want to make sure you have created a file called elementapi.php and it is in your /craft/config/ directory. For ...
Damon's user avatar
  • 4,706
3 votes
Accepted

Using setExpires on returnJson

If you're running Craft CMS 2.6.2783, you can pass in an 'expires' key to the optional $options 2nd parameter of returnJson with the value set to the time in seconds that will be passed to the cache ...
Brad Bell's user avatar
  • 67.5k
3 votes

Craft 3 Plugin Controller - returnJson() replacement?

I wasn't rtfm'ing hard enough. In the docs for \yii\web\Controller, which is what the \craft\web\Controller class extends (which is what your plugin controllers extend) there is a method asJson(). ...
JamesNZ's user avatar
  • 947
3 votes
Accepted

How to store custom data into a user

There are a whole bunch of ways to do what you want to do. You can add custom fields to user accounts. If you wanted to go with option 2 then you could create a custom text field and write the JSON ...
foamcow's user avatar
  • 2,029
3 votes

Limiting entries object when using as json_encode

As per the docs: Element queries are specialized query builders under the hood, so they support most of the same methods provided by craft\db\Query. ...So, in your case you could use select() to ...
James Smith's user avatar
  • 5,344
3 votes

Jsondecode in element API causing memory issue

For an API that deals with a large amount of data, you want to avoid loading all objects into memory. Bumping up the memory limit is only a stop-gap measure, as you said. A couple of approaches to ...
MoritzLost's user avatar
  • 11.5k
3 votes

How to retrieve (& output via twig) one key pair of json object stored i a database column

If you know there's only one row you're interested in, you can execute the query with .one() instead of .array(), this will give you a single result row as an associative array instead of an array of ...
MoritzLost's user avatar
  • 11.5k
2 votes
Accepted

Element API User example

If you set the elementType to User, then the transformer will have a UserModel object passed in like so: <?php namespace Craft; return [ 'endpoints' => [ 'players.json' => [ ...
Brad Bell's user avatar
  • 67.5k
2 votes

Element API + JSON data in template

I can't think of a clean way to do this. The Element API plugin currently will set JSON headers on the response and return the data JSON encoded, so it's not easy to directly embed in a template. A ...
Brad Bell's user avatar
  • 67.5k
2 votes
Accepted

How to skip the first X entries using ElementAPI

We just released Element API 2.6.0 with added support for the offset criteria param, in combination with paginate => true. (Thanks to @missmatsuko for posting a GitHub issue about it: https://...
Brandon Kelly's user avatar
2 votes

Access Element API JSON in another environment

I don't know whether you've seen this answer to another similar question, but it might get you a bit closer: Ajax Post to guestEntries/saveEntries from another domain You could maybe combine what ...
Steve Holland's user avatar
2 votes
Accepted

JQuery $.ajax ":success" form logic with Plugin Controller?

The issue was that curl was, by default, returning the result of the http request to the WebToLead servlet directly, rather than only storing it as $result. This raw HTML response was super-ceding the ...
Aiden Bordner's user avatar

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