Here are a few common tasks you might do in your templates, as they would be written in ExpressionEngine vs. Craft CMS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add / Update a key-value pair in the URL query parameters | |
function updateUrlParameter(uri, key, value) { | |
// remove the hash part before operating on the uri | |
var i = uri.indexOf('#'); | |
var hash = i === -1 ? '' : uri.substr(i); | |
uri = i === -1 ? uri : uri.substr(0, i); | |
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i"); | |
var separator = uri.indexOf('?') !== -1 ? "&" : "?"; | |
if (uri.match(re)) { |
Effective September 2021, Dropbox will be deprecating long-lived access tokens.
This GIST generally describes how to authenticate requests to Dropbox API v2, for anyone working on a server-side PHP Dropbox implementation.
It's important to understand three types of codes you'll encounter:
- Access Code - this is a one-time code that represents user-granted app access.
- Access Token - this is short-lived token that provides access to Dropbox API endpoints.
- Refresh Token - this is a long-lived token that allows you to fetch a fresh Access Token.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (isset($_GET['ajax'])) { | |
session_start(); | |
$handle = fopen('/private/var/log/system.log', 'r'); | |
if (isset($_SESSION['offset'])) { | |
$data = stream_get_contents($handle, -1, $_SESSION['offset']); | |
echo nl2br($data); | |
} else { | |
fseek($handle, 0, SEEK_END); | |
$_SESSION['offset'] = ftell($handle); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* html_convert_entities($string) -- convert named HTML entities to | |
* XML-compatible numeric entities. | |
*/ | |
function html_convert_entities($string) { | |
return preg_replace_callback('/&([a-zA-Z][a-zA-Z0-9]+);/S', | |
'convert_entity', $string); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* HKDF | |
* | |
* @link https://tools.ietf.org/rfc/rfc5869.txt | |
* @param $key Input key | |
* @param $digest A SHA-2 hashing algorithm | |
* @param $salt Optional salt | |
* @param $length Output length (defaults to the selected digest size) | |
* @param $info Optional context/application-specific info | |
* @return string A pseudo-random key |
Stash 2.3.4 (beta) or later
/layouts/
standard.html
/partials/
listing.html
With Stash you have always been able to create global variables and evaluate them in the same template using if/else conditionals:
{exp:stash:set_value name="var" value="cheese" type="snippet"}
{if var == "cheese"}
We have cheese!
{if:else}
Where's the cheese, gromit?
{/if}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Module; | |
(function (Module) { | |
'use strict'; | |
var Greeter = (function () { | |
// Define the Greeter class: | |
function Greeter(message) { | |
this.greeting = message; |
NewerOlder