Skip to content

Instantly share code, notes, and snippets.

Sam Hernandez samhernandez

Block or report user

Report or block samhernandez

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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 / EntryAssetValidateModule.php
Created May 16, 2019
Craft 3 - validate asset elements on entry save example
View EntryAssetValidateModule.php
namespace modules;
use Craft;
use craft\elements\Asset;
use craft\elements\Entry;
use yii\base\Event;
* File: modules/EntryAssetValidationModule.php
samhernandez / craft-contact-form-axios.html
Last active Jan 31, 2019
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 Nov 12, 2019
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 May 27, 2019
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:

samhernandez / matrix-blocks-example.twig
Created Feb 28, 2018
An example of accessing matrix fields and blocks dynamically
View matrix-blocks-example.twig
{# Craft 2 example #}
{# These are identical in function #}
{% set matrixField = entry.myMatrixField %}
{% set matrixField = entry['myMatrixField'] %}
Use contatenation to access entry fields dynamically.
If in the first loop, this is the same as `entry.myMatrixField_1`
You can’t perform that action at this time.