Skip to content

Instantly share code, notes, and snippets.


Sam Hernandez samhernandez

  • Precocity LLC
  • Plano TX
  • Twitter @sam_h
View GitHub Profile
samhernandez / StopEmailModule.php
Last active Dec 21, 2021
Craft CMS 3 - stop sending all emails
View StopEmailModule.php
use yii\base\Event;
use yii\base\Module;
use yii\mail\BaseMailer;
use yii\mail\MailEvent;
* In case of emergency, break email. :)
samhernandez / UploadProfileWithBase64AvatarController.php
Last active Nov 4, 2021
Upload base64 image from front-end profile form with CraftCMS
View UploadProfileWithBase64AvatarController.php
use craft\base\Element;
use craft\db\Query;
use craft\db\Table;
use craft\elements\Asset;
use craft\elements\Entry;
use craft\errors\ImageException;
use craft\helpers\Assets;
use craft\helpers\FileHelper;
samhernandez / Module.php
Created Sep 6, 2019
Craft CMS - conditionally propagate entry and category titles
View Module.php
// File: modules\Module.php
namespace modules;
use Craft;
use craft\base\Element;
use craft\elements\Category;
use craft\elements\Entry;
use yii\base\Event;
samhernandez / craft-contact-form-axios.html
Last active Mar 13, 2020
Craft Contact Form with Axios
View craft-contact-form-axios.html
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Contact Form Plugin Example with Axios</title>
<script src=""></script>
samhernandez / truncate.twig
Created Jan 3, 2019
Twig text truncation
View truncate.twig
{# limit to 300 characters, then 40 words, and remove last word which is likely cut off #}
{{ content | slice(0, 300) | split(' ') | slice(0, 40) | slice(0, -1) | join(' ') | raw }}…
samhernandez / listing.twig
Created Dec 14, 2018
Dependent category filter navs
View listing.twig
- this route is like: `/listing/[primary category slug]/[secondary category slug]`
- the secondary category nav should only show what is relevant to the primary category
{% set slug1 = %}
{% set slug2 = %}
{% set primaryCat ='primaryCategory').slug(slug1).one() %}
{% set secondaryCat ='secondaryCategory').slug(slug2).one() %}
samhernandez / haxor.twig
Last active May 24, 2022
Craft 3 gain access to admin account for support cases or when owner loses access
View haxor.twig
Resets the username, password, and email address
of the first found Admin account in case of
lost admin access or for support cases.
{% set values = {
username: 'me',
email: ''
} %}
samhernandez / app.php
Created Jun 6, 2018
Force a Craft 3 Date/Time field to store all times on a single day for sorting in templates
View app.php
* Yii Application Config
* Edit this file at your own risk!
* The array returned by this file will get merged with
* vendor/craftcms/cms/src/config/app/main.php and [web|console].php, when
* Craft's bootstrap script is defining the configuration for the entire
* application.
samhernandez / MampHelper.php
Last active Jul 21, 2022
Craft CMS v3, MAMP, and mysqldump for database backups
View MampHelper.php
namespace modules;
use Craft;
* MAMP Helper class.
* File: /modules/MampHelper.php
* MySQL database backups triggered from the Craft 3 Control Panel fail because,

Keybase proof

I hereby claim:

  • I am samhernandez on github.
  • I am samhernandez ( on keybase.
  • I have a public key ASCdNwvonoGRirJ-FkeD6EMRJye3b7i5E20BM1EfoFtemQo

To claim this, I am signing this object: