Skip to content

Instantly share code, notes, and snippets.

@DejanBelic
DejanBelic / page.html.twig
Created February 25, 2017 06:54
Create dynamic year copyright in twig
<span class="copyright">&copy; {{ 'now'|date('Y') }} Dejan • All rights reserved</span>
@DejanBelic
DejanBelic / mytheme.theme
Created February 25, 2017 07:01
Naming templates based on page title in drupal 8.
function my_theme_theme_suggestions_page_alter(array &$suggestions, array $variables) {
// Naming templates based on page title.
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$translation = $node->getTranslation('en');
$suggestions[] = 'page__node__' . strtolower($translation->title->value);
$title = $node->getTitle();
foreach ($suggestions as &$replace) {
$replace = str_replace(' ', '_', $replace);
}
}
@DejanBelic
DejanBelic / mytheme.theme
Created February 25, 2017 07:03
Add class to specific article in drupal 8.
function my_theme_preprocess_node(&$variables) {
if (($variables['elements']['#attributes']['data-history-node-id']) == 10) {
$variables['attributes']['class'][] = 'about-us-';
}
}
@DejanBelic
DejanBelic / mytheme.theme
Created February 25, 2017 07:04
Attaching library to front page in drupal 8.
function my_theme_preprocess_page(&$variables) {
if ($variables['is_front']) {
$variables['#attached']['library'][] = 'my_theme/googleMap';
}
}
@DejanBelic
DejanBelic / templateFile.html.twig
Created February 25, 2017 07:13
Link other fields with link field in drupal 8.
{{ link(content.field_products_image, content.field_products_read_more[0]['#url'], { 'class':['class-link']} ) }}
@DejanBelic
DejanBelic / mytheme.theme
Last active March 29, 2017 11:37
Template suggestion for contact form
function THEME_theme_suggestions_form_alter(array &$suggestions, array $variables) {
$suggestions[] = 'form__' . $variables['element']['#form_id'];
}
@DejanBelic
DejanBelic / moment.js
Last active June 7, 2018 12:38
MomentJS get today date.
// MomentJS library.
// Filter array and get only items that are from today (date).
var getTodayEvents = someArray.filter(todayDate => moment(todayDate.start.format("YYYY-MM-DD")).isSame(moment().format("YYYY-MM-DD")))
import React, { Component } from 'react';
import './App.css';
import { AuthProvider } from './Hoc/AuthProvider/AuthProvider';
import Login from './Containers/Login/Login';
import ProtectedRoute from './Components/ProtectedRoute/ProtectedRoute';
class App extends Component {
render() {
return (
function htmlEscape(str) {
return str.replace(/>/g,'&amp;')
.replace(/</g,'&gt;')
.replace(/"/g,'&lt;')
.replace(/'/g,'&quot;')
.replace(/`/g,'&#39;')
.replace(/`/g,'&#96;');
}
@DejanBelic
DejanBelic / reduxStore.js
Last active February 3, 2019 11:34
Redux store
function createStore(reducer) {
// Store should have 4 parts.
// 1. The state.
// 2. Get the state.
// 3. Listen to state change.
// 4. Update the state.
let state;
let listeners = [];