Skip to content

Commit

Permalink
Dev: New API method: renderTwig()
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Apr 17, 2018
1 parent 55c82a2 commit a5e1df5
Show file tree
Hide file tree
Showing 3 changed files with 407 additions and 366 deletions.
15 changes: 11 additions & 4 deletions application/core/LSETwigViewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,19 @@ public function renderTemplateFromFile($sLayout, $aDatas, $bReturn)
* Extendable to use admin templates in the future currently running on pathes, like the yii render methods go.
* @param string $sLayout the name of the layout to render
* @param array $aDatas the datas needed to fill the layout
* @param boolean $bReturn if true, it will return the html string without rendering the whole page. Usefull for debuging, and used for Print Answers
* @param boolean $bReturn if true, it will return the html string without rendering the whole page.
* Usefull for debuging, and used for Print Answers
* @param boolean $bUseRootDir Prepend application root dir to sLayoutFilePath if true.
* @return string HTML
*/
public function renderViewFromFile($sLayoutFilePath, $aDatas, $bReturn = false)
public function renderViewFromFile($sLayoutFilePath, $aDatas, $bReturn = false, $bUseRootDir = true)
{
$viewFile = Yii::app()->getConfig('rootdir').$sLayoutFilePath;
if ($bUseRootDir) {
$viewFile = Yii::app()->getConfig('rootdir').$sLayoutFilePath;
} else {
$viewFile = $sLayoutFilePath;
}

if (file_exists($viewFile)) {
$line = file_get_contents($viewFile);
$sHtml = $this->convertTwigToHtml($line, $aDatas);
Expand All @@ -104,7 +111,7 @@ public function renderViewFromFile($sLayoutFilePath, $aDatas, $bReturn = false)
throw new CException(
sprintf(
gT("Can't render layout %s. Please check the view exists or contact your admin."),
$sLayoutFilePath
$viewFile
)
);
}
Expand Down

0 comments on commit a5e1df5

Please sign in to comment.