Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Handy Craft Tips & Tricks

Handy Craft Tips & Tricks

DotAll 2017
For more information, check out the Paper doc https://paper.dropbox.com/doc/Craft-Tips-Tricks-Y1carV2kW1IS9FKXlEzcS

Alex Van Holtz

October 23, 2017
Tweet

Other Decks in Technology

Transcript

  1. This presentation is better viewed on Dropbox Paper You can

    copy & paste code much easier and I provide a 
 bunch of documentation URLs. https://paper.dropbox.com/doc/Craft-Tips-Tricks-Y1carV2kW1IS9FKXlEzcS
  2. Handy Craft Tips & Tricks 1. Content builders 2. Custom

    Redactor formatting* 3. Add fields to images 4. Router page template 5. The best of Twig 6. Handy General settings 7. Add custom table attributes to element listings* 8. Add custom sources to element listings* 9. Move home out of a single and into a structure 10. Field organization
  3. Content builders Each matrix block represents a single field. •

    [Matrix Field] Simple Content Builder • [Matrix Block] Heading • [Plaintext] Heading • [Matrix Block] Sub Heading • [Plaintext] Sub Heading • [Matrix Block] Body • [Richtext] Text • [Matrix Block] Button • [Plaintext] Button Text • [Plaintext] Button Link • [Asset Selector] Button Download Simple example
  4. Content builders Each matrix block represents a group of fields.

    • [Matrix Field] Complex Content Builder [Matrix Block] Copy Block [Plaintext] Heading [Richtext] Body [Entry Selector] CTA [Asset Selector] Background Image [Entry Selector] Themes Complex example - Copy Block
  5. Content builders Each matrix block represents a grouping of fields.

    • [Matrix Field] Complex Content Builder [Matrix Block] Image Copy Block [Richtext] Heading [Richtext] Body [Entry Selector] CTA [Asset Selector] Image [Dropdown] Image alignment [Option] Align Left [Option] Align Right [Entry Selector] Themes Complex example - Image Copy Block
  6. Content builders • Documentation structure • Faster development • Randomly

    creating blocks with all the themes & options with URL params • Custom field types for each content block Advanced ideas
  7. Custom Redactor formatting • To add a new set of

    config options, add a new JSON file to the Redactor folder within config Create a new config
  8. Custom Redactor formatting • Rich Text fields give a Redactor

    config selector • Check out the redactor docs to see everything you can do
 https://imperavi.com/ redactor/docs/settings/ buttons/ Standard & Simple options
  9. Custom Redactor formatting • Removes everything but formatting options, bold

    and italic • Limits formatting options to paragraph, quote block and h4 tags Modify default formatting options
  10. Custom Redactor formatting • Removes everything but formatting options and

    HTML view • Adds custom formatting options to wrap the selected text with a span that has a class of orange- text or green-text Add custom formatting options
  11. Custom Redactor formatting • Create a simple plugin with just

    just the base plugin file and a resources directory with a css file • Include the css file in the init function if the request is a CP request and if a user is logged in Add CSS to reflect front-end styles
  12. Custom Redactor formatting • You can use an inspector tool

    to see what the class is on the redactor dropdown item and text edit box, then target it in CSS • Updates to Redactor can break this functionality (sometimes they change class names), so keep an eye out Add CSS to reflect front-end styles
  13. Adding fields to image assets • Sometimes you want to

    use a completely different image for different contexts • Transforms won’t always make your designer happy • It saves you from adding extra fields on your entry that won’t necessarily be used Why do it?
  14. Adding fields to image assets You should always define a

    base image. I accomplish this by creating 3 image sources. • [Asset Source] Base Images (width x height) • [Plaintext] Alt • [Category] Category • [Asset] Video - uploads into Videos source • [Asset] Overlay SVG - uploads into Images source • [Asset] Square Image - uploads into Images source • [Asset] Listing Image - uploads into Images source • [Asset Source] Images (mixed sizes) • [Asset Source] Videos (width x height) Avoiding image inception
  15. Router page template • Whenever creating a new section, I

    use the same router template • It’s easier to add, remove and consolidate page templates without modifying the CP • Can create more complex routes What does this mean?
  16. Handy General settings Open up the following file to take

    a look at Craft’s default settings and an explanation of what they do /craft/app/etc/config/default/general.php Default config settings
  17. Handy General settings • This is, without a doubt, my

    favorite setting • Enabling fuzzy search will allow you to find images and entries in a search bar by only providing a partial match of the keyword Fuzzy Search
  18. Handy General settings • By default, upon logging in, the

    user is directed to the dashboard • You can provide a different path to be redirected to upon login Post CP Login Redirect
  19. Handy General settings • By default, Craft allows the user

    to manually update the CMS and some plugins • This option allows us to remove the ability to do so, saving us from click-happy clients • It does not remove the badge letting us know there are updates available Disable auto updates
  20. Handy General settings • Prevents “Forgot Password” forms from revealing

    whether a valid email address was entered • If the email was invalid, a “Password reset email sent” message will be displayed Prevent user enumeration
  21. Handy General settings • Whether the ‘X-Powered- By: Craft CMS’

    header should be sent along with each request Powered by header
  22. Handy General settings • The URI segment Craft should look

    for when determining if the current request should route to the CP rather than the front- end website Change login URI
  23. Add custom table attributes We’re going to add a couple

    of methods to the plugin file we made earlier defineAdditionalEntryTableAttributes() getEntryTableAttributeHtml(EntryModel $entry, $attribute) How do we do this?
  24. Add custom table attributes defineAdditionalEntryTableAttributes() getEntryTableAttributeHtml(EntryModel $entry, $attribute) defineAdditionalAssetTableAttributes() getAssetTableAttributeHtml(AssetFileModel

    $asset, $attribute) defineAdditionalCategoryTableAttributes() getAssetTableAttributeHtml(CategoryModel $cat, $attribute) defineAdditionalCategoryTableAttributes() getCategoryTableAttributeHtml(UserModel $user, $attribute) You can do this for entries, assets, users and categories
  25. Add custom sources We’re going to add a method to

    the plugin file we made earlier 
 modifyAssetSources(&$sources, $context) How do we do this?
  26. Move Home into a structure • Navigate to Settings >

    Sections • Delete the Homepage Single • Navigate to Entries and create a Home entry in the desired structure • Change the slug to __home__ • Save the entry and that’s it! Instructions
  27. Handy Craft Tips & Tricks 1. Content builders 2. Custom

    Redactor formatting 3. Add fields to images 4. Router page template 5. The best of Twig 6. Handy General settings 7. Add custom table attributes to element listings 8. Add custom sources to element listings 9. Move home out of a single and into a structure 10. Field organization