Introduction

Tightening your Craft CMS Security Belt, Sprig Tips, Vanity URLs, and more.

Due to the way the calendar fell in July, it’s been three weeks since the previous issue. That means what follows is an issue packed with lots of great Craft links.

The issue kicks off with a new episode of devMode discussing SEOmatic’s recent critical security release.

There are several links that will help you get the most out of Ben Croker’s recent Sprig plugin. There's a summary of a Craft Discord discussion on making vanity URLs in your Craft sites, plus there are other tips and plugins.

Thank you to the sponsors of this issue.

Fortrabbit is a preferred hosting provider for Craft CMS, offering a modern PHP application platform tailored for Craft, with Git deployments and Composer support. Try fortrabbit today.

Freeform is the feature-filled form plugin for Craft CMS that includes ready-to-use templates to get you up and running quickly. Learn about the power of Freeform.

Let’s hit the links.

-John Morton

Craft Link List  

Top Stories

News




Featured Sponsor

Tools, tips, and fundamentals

What template are you rendering?

h/t Adrea for pointing this little Twig function.

{{  _self  }}

For a more robust solution, check out Andrew's Template Comment plugin.

Craft Link List  

Vanity URLs in Craft

In Discord a couple of weeks ago, a user asked how you can allow content authors to create vanity URLs within the control panel pointing to specific entries. For example, the URL example.com/my-vanity-url would link to example.com/products/some-product, meaning the canonical URL would be example.com/products/some-product.

Brandon suggested creating a vanityUri field that holds the value. Then in the config/routes.php add this to the bottom of the array, which creates a catch-all rule if nothing else matched:

return [
    // ...
    '<vanityUri:(.+)>' => ['template' => '_vanity'],
];

Then create a _vanity.twig template with this:

{# see if an entry matches the URI #}
{% set entry = craft.entries()
  .vanityUri(vanityUri)
  .one() %}

{% if not entry %}
  {% exit 404 %}
{% endif %}

{# Include the normal entry template #}
{% include (entry.section.siteSettings|first).template %}

Notice that the 404 triggering is now done in this template.

Craft Link List  












Perfecting your technique







Sponsor

Plugged In








The Craft Advantage

Overheard

It’s not Craft, but it’s interesting.