Skip to content

Instantly share code, notes, and snippets.

@rodebert
Created February 10, 2015 16:52
Show Gist options
  • Save rodebert/aea57e1e94ebce5b49cc to your computer and use it in GitHub Desktop.
Save rodebert/aea57e1e94ebce5b49cc to your computer and use it in GitHub Desktop.
Statamic plugin to check if variable contains a string
<?php
class Plugin_contains extends Plugin {
public function index() {
$needle = $this->fetchParam('needle', '', null, false, false);
$haystack = $this->context[$this->fetch('haystack')];
return strpos($haystack, $needle) ? $this->content : false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment