Skip to content

Instantly share code, notes, and snippets.

View jasonglisson's full-sized avatar

Jason Glisson jasonglisson

View GitHub Profile
<ol>
{% for key, value in _context %}
<li>{{ key }}</li>
{% endfor %}
</ol>
Or you can use:
{{ dump(_context|keys) }}
@jasonglisson
jasonglisson / add_to_menu.php
Last active September 14, 2017 12:41
Wordpress - Append this to the end of the main menu
function add_last_nav_item($items) {
return $items .= '<li><a href="#myModal" role="button" data-toggle="modal">Contact</a></li>';
}
add_filter('wp_nav_menu_items','add_last_nav_item');
@jasonglisson
jasonglisson / new_gist_file_0
Last active September 14, 2017 12:41
Disable all non-core modules
drush pml --no-core --type=module --status=enabled --pipe | xargs drush -y dis
@jasonglisson
jasonglisson / new_gist_file_0
Last active September 14, 2017 12:41
Wordpress - Print out content in a page template
<?php
while ( have_posts() ) : the_post(); ?> <!--Because the_content() works only inside a WP Loop -->
<div class="entry-content-page">
<?php the_content(); ?> <!-- Page Content -->
</div><!-- .entry-content-page -->
<?php
endwhile; //resetting the page loop
wp_reset_query(); //resetting the page query
?>
@jasonglisson
jasonglisson / menu-depth
Last active September 14, 2017 12:41
Drupal 7: Embed menu with particular depth
$menu_depth = 1;
print drupal_render(menu_tree_output(menu_tree_all_data('my-custom-menu', null, $menu_depth)));
isset($_GET['mykey']) ? $_GET['mykey'] : ""
@jasonglisson
jasonglisson / new_gist_file_0
Last active September 14, 2017 12:41
Drush Commands
Sync DB between two boxes - drush sql-sync @dev @jasons
Sync files between two boxes - drush rsync @dev:%files @jasons:%files
@jasonglisson
jasonglisson / strong-passwords.php
Created June 27, 2016 21:23 — forked from tylerhall/strong-passwords.php
A user friendly, strong password generator PHP function.
<?PHP
// Generates a strong password of N length containing at least one lower case letter,
// one uppercase letter, one digit, and one special character. The remaining characters
// in the password are chosen at random from those four sets.
//
// The available characters in each set are user friendly - there are no ambiguous
// characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option,
// makes it much easier for users to manually type or speak their passwords.
//
// Note: the $add_dashes option will increase the length of the password by
@jasonglisson
jasonglisson / views_template_module.php
Last active September 14, 2017 12:41
Drupal 7 - Have module load in views templates
function NAME_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'NAME'),
'template path' => drupal_get_path('module', 'NAME'),
);
}
This will tell Views to look in the root directory of your module. I personally am a fan of adding a subdirectory to the module to hold template files. To do this append the directory name to the end of the template path, eg:
'template path' => drupal_get_path('module', 'NAME') . '/templates',
@jasonglisson
jasonglisson / table_render.php
Last active September 14, 2017 12:41
Render table in PHP
$rows = 1;
if (($handle = fopen("<path to csv file>", "r")) !== FALSE) {
echo '<table class="table table-bordered toggle-square-filled default breakpoint footable">';
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
if ($rows == 1) {
echo '<thead><tr>';