Commit
…erride core views
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,40 @@ public function addExtensions($extensions) | |
} | ||
} | ||
|
||
|
||
/** | ||
* Renders a view file. | ||
* This method is required by {@link IViewRenderer}. | ||
* @param CBaseController $context the controller or widget who is rendering the view file. | ||
* @param string $sourceFile the view file path | ||
* @param mixed $data the data to be passed to the view | ||
This comment has been minimized.
Sorry, something went wrong. |
||
* @param boolean $return whether the rendering result should be returned | ||
* @return mixed the rendering result, or null if the rendering result is not needed. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
LouisGac
Contributor
|
||
*/ | ||
public function renderFile($context, $sView, $aData, $bReturn=true) | ||
{ | ||
global $thissurvey; | ||
$requiredView = Yii::getPathOfAlias('application.views').$sView; | ||
if(isset($thissurvey['template'])) | ||
{ | ||
$sTemplate = $thissurvey['template']; | ||
$oTemplate = Template::model()->getInstance($sTemplate); // we get the template configuration | ||
if($oTemplate->overwrite_question_views===true && Yii::app()->getConfig('allow_templates_to_overwrite_views')) // If it's configured to overwrite the views | ||
{ | ||
$requiredView = $oTemplate->viewPath.ltrim($sView, '/'); // Then we check if it has its own version of the required view | ||
if( file_exists($requiredView.'.php') ) // If it the case, the function will render this view | ||
{ | ||
Yii::setPathOfAlias('survey.template.view', $requiredView); // to render a view from an absolute path outside of application/, path alias must be used. | ||
$sView = 'survey.template.view'; // See : http://www.yiiframework.com/doc/api/1.1/CController#getViewFile-detail | ||
} | ||
} | ||
} | ||
|
||
// Twig or not twig? | ||
if( file_exists($requiredView.'.twig') ){ | ||
return parent::renderFile( Yii::app()->getController(), $requiredView.'.twig', $aData, $bReturn); | ||
}else{ | ||
return Yii::app()->getController()->renderPartial($sView, $aData, $bReturn); | ||
} | ||
} | ||
} |
10 comments
on commit a8f1aa9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now, anywhere in frontend, we can use:
app()->twigRenderer->renderFile( Yii::app()->getController(), $sView, $aData, $bReturn);
it will use the template view if exists, else the core one. It accepts php files like twig files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really usage of global $thissurvey ?
And update $requiredView is template is allowed to $oTemplate->viewPath.ltrim($sView, '/');
And use it after without reset it in if( file_exists($requiredView.'.twig') ){
Then :
- set allow_templates_to_overwrite_views in config + overwrite_question_views in template
- Don't put any files in $oTemplate->viewPath
- Test the survey : send error about a file don't exist.
No ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ever the case that first argument is not getController()
?
Edit: OK, can be widget, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phpdocs arguments must be named same as in function signature, otherwise scrutinizer will complain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scrutinizer can whine as a cry baby ^^
about the first argument hell, it's because of the interface that force the signature of the method....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about making a wrapper function as the internal API instead? Less writing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, $context
is not used. More scrutinizer complains. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shnoulle: I still didn't tested to overwrite a view. I suppose it's working. I'll test it now.
@olle: for the controller first argument? Yep, I was thinking about something like that.
@scrutinizer: http://m.memegen.com/r7un8v.jpg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not about overwriting a view ability ... its' just : code is broken ....
About : scrutinizer : don't copy paste, use @ see
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array
, notmixed