Skip to content

Instantly share code, notes, and snippets.

@Alexander-Pop
Alexander-Pop / Find-element-in-an-array-with-JavaScript.js
Last active October 26, 2021 09:04
Find element in an array with JavaScript #javascript #array
let charts = {
curationstate: "Curation State",
modellingapproach: "Modelling Approach",
organism: "Organism",
journal: "Journal"
};
// Note: the three equal signs so that null won't be equal to undefined
if (charts["curationstate"] === undefined) {
// do something
@Alexander-Pop
Alexander-Pop / onclick-add-parameter.js
Last active June 28, 2021 16:03
Jquery - onclick add parameter to url of other element #jquery #click
$("#classdemo-about img").click(function(){
//console.log('yes');
$('.btn-primary').attr('href', function() {
var vpar = '?vid=1';
if (this.href.indexOf(vpar) == -1) {
return this.href + vpar;
}
});
})
@Alexander-Pop
Alexander-Pop / session-test.php
Created May 1, 2021 16:17
[Session test] #php #session #server
<?php
// Start Session
session_start();
// Show banner
echo '<b>Session Support Checker</b><hr />';
// Check if the page has been reloaded
if(!isset($_GET['reload']) OR $_GET['reload'] != 'true') {
// Set the message
$_SESSION['MESSAGE'] = 'Session support enabled!<br />';
// Give user link to check
@Alexander-Pop
Alexander-Pop / .htaccess Some Useful Redirects
Last active April 18, 2021 14:00
Some Useful Redirects using .htaccess #htaccess #redirect
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@Alexander-Pop
Alexander-Pop / Removing-the-Default-Drupal-Page-Title-Per-Content-Type.php
Last active April 16, 2021 10:37
Drupal 8 - Removing the Default Drupal Page Title per content type #drupal8
<?php
use Drupal\node\Entity\Node;
function YOURTHEME_preprocess_page(&$variables) {
if (isset($node) && $node instanceof Node) {
// Create variable out of the current node type
$node_type = $node->getType();
// Remove page title block.
if (($node_type == 'you_content_type_system_name') || ($node_type == 'you_other_content_type_system_name')) {
unset($variables['page']['content']['YOURTHEME_page_title']);
@Alexander-Pop
Alexander-Pop / GoogleMerchantFeedexample.xml
Created January 26, 2021 15:53
Google Merchant - Feed example in xml #xml #feed
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
<channel>
<title>
<![CDATA[ Data feed Title ]]>
</title>
<link>
<![CDATA[ http://www.website.com ]]>
</link>
<description>
<![CDATA[ Data feed description. ]]>
@Alexander-Pop
Alexander-Pop / List-all-content-of-the-same-Term.txt
Created January 21, 2021 23:48
Drupal 8 - List all content of the same Term(s) #drupal8 #term #view #content #category
Create a new content based block view - Related Items (or something) add fields to it. We will need to use 2 contextual filters. Id and Has taxonomy term id.
Configure Id filter as following:
Provide default value: Content ID from URL
Under More tab - Check next to Exclude
Configure Has taxonomy term id as following:
Provide default value: Taxonomy term ID from URL
@Alexander-Pop
Alexander-Pop / laravel-loop.php
Last active January 20, 2021 13:37
Laravel 8 - blade loops #laravel #blade #laravel-loop #foreach
@if ($products->count())
@foreach($products as $product)
<div @if ($loop->name) class="foo-class" @endif>
//$loop was auto added ($loop->first, $loop->last, $loop->odd, $loop->even, $loop->interation, $loop->index)
somethinh
</div>
@if ($product->price > 2000) @breake @endif
@endforeach
@else
No products found
@Alexander-Pop
Alexander-Pop / List-all-content-of-the-same-Author.txt
Created January 13, 2021 01:55
Drupal 8 - List all content of the same Author #drupal8 #author #view #content
STEPS:
1. Start creating a new view by clicking "Add new view" link under Admin > Structure > Views.
2.
a) Type "Other Contents by Author" in "View name" text box.
b) [Optional step.] You can check "Description" checkbox and write a description for view. If you wish, check and write "A list which contains other content by author."
3. Select "Content" from the "Show" select list.
4. Uncheck "Create a page".
@Alexander-Pop
Alexander-Pop / Show-Author-Info-in-a-Block.txt
Created January 13, 2021 01:52
Drupal 8 - Show Author's Info in a Block #drupal #block #author
Creating Views: Author info
1. Go to Structure>Views.
2. Add new view: Author Info. Select Users in views setting. Select Create a block in Block setting. Set Unformatted list of Filed under Block display settings. Select 1 under items per block. Click->Save and edit.
3. Views setting page:
4. Now add Relationship: Go under Advanced setting. under relationship click add and from the list select Content Author, give it a name Author node (optional)
5. Now add contextual filter: Same as above step, click add to contextual filter. select ID. And select Provide default value. Under that select Content ID from Url.