Smarty


Smarty blank white page 1

A common reason for the blank white page is an error in the smarty template syntax.  Check for unclosed brackets or comment out blocks of code and refresh the page and see if it works.

Another possibility is permissions.  I recently created a branch in our code repository so I could work on a new feature for our application.  After I performed a checkout of the code and altered my config file to work with the new directory I created on my local server, only a blank white page would display.  I tried setting the $debugging variable in smarty to true so I could view the debug output in a popup window, but that didn’t work either.  Long story short and six hours later, I was again messing with permissions on smarty’s templates_c directory on windows.  I unchecked the “read only” checkbox on windows a dozen times (it comes back as checked automagically everytime) and that didn’t work.  In the past, as long as the “everyone” user had full control of the directory, then all was good.  Not this time.  I was pretty fed up with this not working and was trying anything to get something on the screen other than a blank white page.  In the directory security, I gave full control to every user available and walla… It works!!!  Hope this will help somebody else.



Smarty template logic 1

Our development team had a bit of a disagreement and discussion today on where logic should go when using Smarty.  My personal belief was that when using the MVC design pattern like we do, logic should go in the controller and not in the view layer (smarty template).

The existing code was as follows:

1
2
<!-- controller -->
$smarty->assign('pageAction', $_GET['pageAction']);
1
2
3
4
5
6
7
8
9
<!-- smarty template (view) -->
<h2>
DNS Domains 
{if $pageAction == 'viewDisabled'}
	Viewing Disabled
{elseif $pageAction == 'viewPendingActions'}
	Pending Actions
{/if}
</h2>

My belief was to move the logic to the controller and out of the view layer. The change was as follows:

1
2
3
4
5
6
7
8
9
10
11
12
 
// set the page title in the controller and assign variable to smarty
switch($pageAction) {
	case 'viewDisabled':
		$smarty->assign('pageTitle', 'Disabled DNS Domain List');
		break;
	case 'viewPendingActions':
		$smarty->assign('pageTitle', 'Pending Action DNS Domain List');
		break;
	default:
		$smarty->assign('pageTitle', 'DNS Domain List');
}
1
2
<!-- smarty template -->
<h2>{$pageTitle}</h2>

Both methods produce the same result. Is either of them more correct than the other?