From 5396e2c1e6c9796f5305c42800961e34aa1f5ccf Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 9 May 2018 12:51:24 -0600 Subject: [PATCH] Add custom default value option to get_component() --- lib/themefunctions.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/themefunctions.php b/lib/themefunctions.php index 983119c..e0ea8a8 100644 --- a/lib/themefunctions.php +++ b/lib/themefunctions.php @@ -153,21 +153,25 @@ function get_page_url($echo = true, $slug = null) { * @param string $name component name * @param string $context page slug, or null for current * @param boolean $echo default true + * @param string $default The content to return if the component is empty * @return string */ -function get_component($name, $context = null, $echo = true) { +function get_component($name, $context = null, $echo = true, $default = "") { $db = getdatabase(); if ($context == null) { $context = get_page_slug(false); } $pageid = $db->get("pages", "pageid", ["AND" => ["slug" => $context, "siteid" => getsiteid()]]); $content = ""; - if (isset($_GET['edit'])) { - $content = "
"; - } if ($db->has("components", ["AND" => ["pageid" => $pageid, "name" => $name]])) { $content = $db->get("components", "content", ["AND" => ["pageid" => $pageid, "name" => $name]]); } + if ($content == "") { + $content = $default; + } + if ($content == "" && isset($_GET['edit'])) { + $content = "
"; + } if ($echo) { echo $content; } else { @@ -539,4 +543,4 @@ function get_socialmedia_urls() { } } return $urls; -} \ No newline at end of file +}