Skip to content

Instantly share code, notes, and snippets.

@objectivehtml
Created December 14, 2011 21:29
Show Gist options
  • Save objectivehtml/1478635 to your computer and use it in GitHub Desktop.
Save objectivehtml/1478635 to your computer and use it in GitHub Desktop.
A better way to fetch EE parameters
private function param($param, $default = FALSE, $boolean = FALSE, $required = FALSE)
{
$name = $param;
$param = $this->EE->TMPL->fetch_param($param);
if($required && !$param) show_error('You must define a "'.$name.'" parameter in the '.__CLASS__.' tag.');
if($param === FALSE && $default !== FALSE)
{
$param = $default;
}
else
{
if($boolean)
{
$param = strtolower($param);
$param = ($param == 'true' || $param == 'yes') ? TRUE : FALSE;
}
}
return $param;
}
@objectivehtml
Copy link
Author

$param = $this->param('entry_id'); //Most basic usage. Fetches entry_id parameter, if it's not set, returns FALSE

$param = $this->param('entry_id', FALSE, FALSE, TRUE); //Requires an entry_id parameter.

$bool_param = $this->param('include_js', FALSE, TRUE); //Fetches a parameter and if 'true' or 'yes', returns TRUE. If not TRUE then returns FALSE

$default_param = $this->param('dynamic', TRUE, TRUE); //Fetches a boolean value but if param is not set, still returns TRUE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment