Skip to content

Instantly share code, notes, and snippets.

return array(
'*' => array(
'devMode' => false,
'environmentVariables' => array(
'siteUrl' => 'http://economicexperts.eu/'
),
),
'.dev' => array(
@brandonkelly
brandonkelly / relatedTo.twig
Last active December 27, 2015 00:49
New 'relatedTo' element param coming in Craft 1.3
<h3>My favorite cocktails that have gin</h3>
{% set cocktails = craft.entries.section('cocktails').relatedTo('and', {
sourceElement: currentUser,
field: 'favoriteCocktails'
}, {
targetElement: craft.entries.section('ingredients').slug('gin'),
field: 'ingredients'
}) %}
@brandonkelly
brandonkelly / gist:8149062
Last active July 30, 2018 08:26
Saving new Matrix data
<?php
// Get the entry
$entry = craft()->entries->getEntryById(100);
// Convert the existing data to what it would look like in POST
$matrixData = array();
foreach ($entry->matrixField as $block)
{
@brandonkelly
brandonkelly / templating.md
Last active February 7, 2024 15:20
Templating in EE vs. Craft
@brandonkelly
brandonkelly / gist:8672116
Created January 28, 2014 17:26
A function for converting an entry in Craft to JSON
<?php
public function getEntryJson(EntryModel $entry)
{
$entryData = array();
foreach ($entry->getType()->getFieldLayout()->getFields() as $field)
{
$field = $field->getField();
$handle = $field->handle;
@brandonkelly
brandonkelly / gist:8771071
Created February 2, 2014 16:37
Grabbing “parent” Matrix rows, where the Matrix field has a Playa cell that is relating to a given entry.
{exp:channel:entries ... }
{exp:playa:parents field="matrix_field_name" col="playa_col_name" var_prefix="parent"}
{parent:matrix_field search:matrix_col_name="[{entry_id}]" var_prefix="row"}
{row:some_col_name}
{!-- we can even loop through all of those related entries
(which will include the top-level entry) if we want... --}
@brandonkelly
brandonkelly / HttpRequestVariable.php.diff
Created February 17, 2014 23:35
Add a craft.request.getPageNum() function to Craft
diff --git Source/craft/app/variables/HttpRequestVariable.php Source/craft/app/variables/HttpRequestVariable.php
index fad31b7edab84f5c428e3ce2c3b3ec6e8d92e7ef..430e1adcdf801cccabaf67c89001465c8835fba7 100644
--- Source/craft/app/variables/HttpRequestVariable.php
+++ Source/craft/app/variables/HttpRequestVariable.php
@@ -201,4 +201,14 @@ class HttpRequestVariable
{
return craft()->request->isMobileBrowser($detectTablets);
}
+
+ /**
{% macro entryLink(entry, selEntry) %}
{% if entry.type == 'link' %}
<a href="{{ url(entry.linkUrl) }}">{{ entry.title }}<span class="external"></span></a>
{% elseif entry.type == 'headingOnly' %}
{% set nextEntry = entry.getNext() %}
{% if nextEntry %}
<a href="{{ nextEntry.url }}">{{ entry.title }}</a>
{% else %}
{{ entry.title }}
{% endif %}
@brandonkelly
brandonkelly / FieldsVariable.php
Created March 10, 2014 18:55
craft.fields.getFieldByHandle()
<?php
// ...
public function getFieldByHandle($handle)
{
return craft()->fields->getFieldByHandle($handle);
}
<?php
namespace Craft;
class CompatibilityPlugin extends BasePlugin
{
function getName()
{
return Craft::t('Browser Compatibility');
}