What's the deal with Deno? We talk with a major contributor to find out. Listen now.
26

You can do this entirely with Twig. First, use the |split filter to split your HTML into an array of paragraphs, on their closing </p> tags: {% set paragraphs = entry.myRichTextField|split('</p>') %} Then, you can assign the first paragraph to a new variable using the |first filter. And don’t forget to bring back that missing </p>. {% ...


25

The Technical Way You can do this using Twig's template_from_string function and the raw filter. In your template code you would output your Rich Text field: {{ include(template_from_string(entry.richTextFieldHandle)|raw) }} And within your Rich Text field you could reference your global with the same syntax you normally would in Twig as you described ...


18

https://github.com/ryanshrum/hacksaw This hasn't been fully tested for production, or documented for that matter, but I have migrated it over and tested basic usage as per the docs on devot-ee. It should, at the very least, give you a nice start. You can use the Twig filter with: {{ entry.fieldHandle|hacksaw(words="100") }}


16

No need for a plugin, just use twig's slice filter, combined with the striptags filter. I've thrown in the default filter for good measure, in case the body is empty for some reason. {{ entry.body|striptags|slice(0,100)|default('Read more') }}... slice will simply output the first 100 characters (starting at 0 the first character), including spaces into ...


13

Doesn't answer the specific question but based on the title in search results it might be helpful for anyone just wanting to truncate a string: {{ entry.title | length > 75 ? entry.title | slice(0, 75) ~ '...' : entry.title }} Also doesn't require a plugin. Based on this.


13

If by styles you mean the formatting drop-down, just add them in an array: { buttons: ['bold', 'italic'], formatting: ['p', 'blockquote', 'h2', 'h3', 'h4', 'SomeHtmlTag'] } . If you want to have a button which adds custom CSS-classes, take a look at: Redactor CSS by Nathan Doyle Update (July 2015) Craft 2.3.2615 (Dec 2, 2014) and above use ...


11

This is a high-level question, with multiple problems to solve. First, you'll need to parse the HTML from the Rich Text field for <a> tags. Then, you'll need to find a way to match the href attributes for those <a> tags to entries, and finally, you'll need to set classnames to the <a> tags (depending on the matched entry's Entry Type) and ...


10

No need for a plugin. Just add: "imageResizable": true, "imagePosition": true, to your chosen redactor config file i.e. (/craft/config/redactor/standard.json)


9

It's worth noting that as of Craft 2.5, it's now using Redactor II, so the above code examples don't work if you have upgraded. Here's a working JSON config example you can build on: { "buttons": ["format","bold","lists","link","file","image"], "plugins":["source","fullscreen"], "toolbarFixed": true, "formatting": ["p", "blockquote", "h2", "...


9

You can use the formattingAdd config setting to add custom formatting to the "Format" dropdown. formattingAdd: { "align-left": { "title": "Align left", "args": ["p","class","align-left"], }, "align-right": { "title": "Align right", "args": ["p","class","align-right"], }, "align-center": { "title": "Align center", "args": ["...


8

Craft has a parseRefs filter built right in: http://buildwithcraft.com/docs/reference-tags One drag if using globals is that you have to use the globalset's ID, not the handle. e.g. {globalset:34:number}


8

I suggest a Twig filter so you can do something like this in the template: {{ entry.body | wrapembeds }} This is something to love about Craft - the ease of building Twig filters. In the plugins directory create a folder videoembeds. Create the main plugin file WrapEmbedsPlugin.php: <?php namespace Craft; class WrapEmbedsPlugin extends BasePlugin { ...


8

Victor answers my questions regarding the formatting tags and the fact that you need to create a Craft plugin to add Redactor plugins. Since there wasn't a solution for adding classes on inline elements with custom classes/styles, Nathan's plugin only supports block elements, I created a plugin that wraps the Styles Redactor plugin. You can get it here: ...


7

In case anyone is wondering how you get the rest of the text – here is an example: {# Split paragraphs using a limit of 2 #} {% set paragraphs = block.body|split('</p>', 2) %} {# Get first paragraph and add the missing closing tag #} {% set firstParagraph = paragraphs|first ~ '</p>' %} {{ firstParagraph|raw }} {# The rest of the text is here,...


7

When you create a Rich Text field, there is an option for Clean up HTML which is checked by default. The description underneath the setting reads: Removes spans, empty tags, and most style attributes on save. When aligning text in Redactor, inline styling is added, which would be stripped away on save if the Clean up HTML option is checked. You'll just ...


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


7

Either existing answer could work. Another option is a plugin I've recently built. Redactor Extras: https://github.com/elliotlewis/Redactor-Extras Uses the Plugin from Redactors site for align. Has other extras as well.


6

Just looked into this and it’s a Craft bug. If you add an image manually using the “Insert URL” option, the image can be dragged around, but not if you use the “Choose image” option, which opens Craft’s image selection modal. Saving the entry and coming back to it (or just typing Command + S) will also make the image draggable, regardless of how you added ...


6

It turns out Smartdown should do the trick. It's a Craft plugin that adds MarkdownExtra and SmartyPants (the latter of which matters here) support to Twig. SmartyPants is a rather ancient blogging plug-in from John Gruber for intelligently handling smart punctuation. Michel Fortin ran with it in the form of PHP SmartyPants, and most recently this Craft ...


6

If what you want is a multi-line plain text field, then check the Allow line breaks checkbox for that field.


6

You can override the control panel's CSS with a plugin. Use the popular "Control Panel CSS plugin" by Lindsey DiLoreto or make your own little one. Make use of the includeCssResource() function and include a CSS file with your custom redactor styles: myRedactorCssPlugin.php: public function init() { if (craft()->request->isCpRequest()) { ...


6

You can use the striptags filter to remove all HTML tags from your string. With the trim filter you can strip all whitespace from the beginning and the end of it: {% if entry.poorText|striptags|trim %} {{ entry.poorText }} {% else %} Here could be a nicely formatted text! {% endif %}


6

If you only want to style how the link looks visually, and need a work-around, you could use my Redactor Styles for Craft plugin. If you add an inline style to the plugins Styles JSON object like this: [ { "btnName":"Action button", "className":"btn-action", "spanClass":"btn-action" } ] Depending on which order the user creates the link ...


6

Please do yourself a favor and don't do this in Redactor. Find a solution with Matrix (and/or Super Table) to add things like this in-between your text blocks.


5

Just for reference, if you use a regular Rich Text field for an optional custom Post Excerpt and a Matrix field (with a "text" field in it, among others) for the Post Body, you could check the custom excerpt for content and otherwise output the first paragraph of the text field in the first Matrix block of type textBlock: {% for entry in craft.entries....


5

I'm a total novice with Craft/Twig and I was hoping for some sort of simple and neat append function in Twig! However, I've got close to a working solution using CSS, by overriding the Extract's <p> tags' usual behavior with display: inline, and enclosing the 'Continue reading…' in a <span> tag. Edit: The following (including some additional ...


5

For those bumping into this old-ish question and looking for a similar solution: Andrew Welch has recently released a plugin that allows you to pull field values from a globalset. https://github.com/nystudio107/richvariables It's not letting you write Twig templates, but it allows you do achieve what is described in the OP, namely output a custom field ...


5

Not sure if it helps, but I accomplished this using a plain text field (with multi-line enabled). Then I just used CSS to format the field in a way to make it look like a code snippet... Screenshot of field in the Control Panel: I used the Control Panel CSS plugin to add this CSS: #fields-myfieldhandle textarea.nicetext { font-size: 13px; font-...


5

The plugin doesn't come with Craft. You have to manually install it with a Craft plugin, but luckily this is easy to do: Set up your new Craft plugin (→ "Plugin Development - Setting Things Up") Download the Redactor plugin and copy it to craft/plugins/myplugin/resources/ Load the Redactor plugin JS file from the init function: craft()->templates->...


5

You should be OK converting your Plain Text to Rich Text. I've just tried it in my dev environment and everything was preserved. Rich Text will add the paragraph tags as you suggest, so you'll want to remove them from your templates files as you mentioned. If you're being cautious, you can take a backup of your database in the Settings section of your ...


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