Glossary Item Box
Overview
If you are a PHP developer, you might find some of the info below helpful when designing your own themes for Squirrelcart.
Referencing Theme Specific Variables in Your Template Files
Squirrelcart has a feature that allows you to associate merchant supplied data with a theme. You can use this to gather information that you might want to output somewhere in a template file, or to control some custom code entered in a template file. This feature allows you to enable up to 25 fields on a theme's record, which can be altered by a merchant and referenced by you in Squirrelcart's template files.
Adding Config Fields to a Theme's Record
Now that you've added a custom variable to your theme, read the section below to find out how to access it's value.
Accessing Theme Variables in Template Files
All variables entered on a theme's record are available in the PHP array $SC['theme_config'].
Continuing with the example from the section above, we now have a theme that has a text field to gather a greeting to be used in this theme. The steps below explain how you can access the value of this variable for use in your template files. For this example, we will put the greeting on the storefront page right after the store logo.
![]() |
If you haven't already done so, read the topic explaining how to properly modify template files before continuing. |
Theme Setup File - pre_theme.php
How it Works
If you need a place to put your own custom PHP that is specifically related to a theme you are creating, the best place for it is the pre_theme.php file, which can be placed in squirrelcart/themes/YOUR_THEME/.
If your theme contains a pre_theme.php file, Squirrelcart will include that file before including any template files. You can put code in this file to setup special variables you might need access to in your templates.
Security for pre_theme.php
To ensure your pre_theme.php file is not loaded directly via a browser, we recommend adding this as the very first line after your opening PHP tag:
/* This line prevents direct access to template. Don't remove it. */ if (!defined('SC_INCLUDE_OK')) die;
Example
Here is an example of a pre_theme.php file that is used to set some theme_config variables to default values when they are not already set on the theme's record:
<?php
/*********************************************************************************************************************************
pre_theme.php
Purpose: this is not a template file, and should not be modified under normaly circumstances. This file
sets up certain theme specific variables prior to including your template files.
*********************************************************************************************************************************/
/* This line prevents direct access to template. Don't remove it. */ if (!defined('SC_INCLUDE_OK')) die;
// setup variables for phone number and email
$SC['theme_config']['Phone_Number'] = $SC['settings']['Phone_Number'] ? sc_xml_safe($SC['settings']['Phone_Number']) : '888.555.1212';
$SC['theme_config']['Email_Address'] = $SC['settings']['Customer_Service_Email'] ? sc_xml_safe($SC['settings']['Customer_Service_Email']) : 'sales@example.com';
?>
© 2001-2017 Lighthouse Development. All Rights Reserved.