Skip to content

Instantly share code, notes, and snippets.

@Nyalab
Created April 15, 2013 12:37
Show Gist options
  • Select an option

  • Save Nyalab/5387744 to your computer and use it in GitHub Desktop.

Select an option

Save Nyalab/5387744 to your computer and use it in GitHub Desktop.
Know if a partial exists in #symfony1.4
<?php
function partial_exists($templateName)
{
$context = sfContext::getInstance();
// is the partial in another module?
if (false !== $sep = strpos($templateName, '/'))
{
$moduleName = substr($templateName, 0, $sep);
$templateName = substr($templateName, $sep + 1);
}
else
{
$moduleName = $context->getActionStack()->getLastEntry()->getModuleName();
}
// We need to fetch the module's configuration to know which View class to use,
// then we'll have access to information such as the extension
$config = sfConfig::get('mod_'.strtolower($moduleName).'_partial_view_class');
if( empty($config) )
{
require($context->getConfigCache()->checkConfig('modules/'.$moduleName.'/config/module.yml', true));
$config = sfConfig::get('mod_'.strtolower($moduleName).'_partial_view_class','sf');
}
$class = $config.'PartialView';
$view = new $class($context, $moduleName, $templateName, '');
$templateName = '_'.$templateName.$view->getExtension();
//We now check if the file exists and is readable
$directory = $context->getConfiguration()->getTemplateDir($moduleName, $templateName);
if($directory)
{
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment