Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1228 from wmde/page_display_handler
Load custom templates for content pages
- Loading branch information
Showing
11 changed files
with
206 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare( strict_types = 1 ); | ||
|
||
namespace WMDE\Fundraising\Frontend\App\RouteHandlers; | ||
|
||
use Silex\Application; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use WMDE\Fundraising\Frontend\Factories\FunFunFactory; | ||
use WMDE\Fundraising\Frontend\Presentation\ContentPage\ContentNotFoundException; | ||
use WMDE\Fundraising\Frontend\Presentation\ContentPage\PageNotFoundException; | ||
use WMDE\Fundraising\Frontend\Presentation\TwigTemplate; | ||
|
||
/** | ||
* @license GNU GPL v2+ | ||
* @author Tim Eulitz < tim.eulitz@wikimedia.de > | ||
* @author Gabriel Birke < gabriel.birke@wikimedia.de > | ||
*/ | ||
class PageDisplayHandler { | ||
|
||
private $ffFactory; | ||
private $app; | ||
|
||
public function __construct( FunFunFactory $ffFactory, Application $app ) { | ||
$this->ffFactory = $ffFactory; | ||
$this->app = $app; | ||
} | ||
|
||
function handle( $pageName ) { | ||
$pageSelector = $this->ffFactory->getContentPagePageSelector(); | ||
|
||
try { | ||
$pageId = $pageSelector->getPageId( $pageName ); | ||
} | ||
catch ( PageNotFoundException $exception ) { | ||
throw new NotFoundHttpException( "Page page name '$pageName' not found." ); | ||
} | ||
|
||
try { | ||
return $this->getPageTemplate( $pageId )->render( [ 'page_id' => $pageId ] ); | ||
} | ||
catch ( \Twig_Error_Runtime $exception ) { | ||
if ( $exception->getPrevious() instanceof ContentNotFoundException ) { | ||
throw new NotFoundHttpException( "Content for page id '$pageId' not found." ); | ||
} | ||
|
||
throw $exception; | ||
} | ||
} | ||
|
||
/** | ||
* Checks if file matching page ID exists in page_layouts directory and loads template if it exists | ||
* Otherwise, falls back to base.twig template | ||
* | ||
* @param string $pageId | ||
* @param array $context Additional variables for template | ||
* | ||
* @return TwigTemplate | ||
*/ | ||
public function getPageTemplate( string $pageId, array $context = [] ): TwigTemplate { | ||
$template = 'page_layouts' . DIRECTORY_SEPARATOR . 'base.html.twig'; | ||
$pageTemplate = 'page_layouts' . DIRECTORY_SEPARATOR . $pageId . '.html.twig'; | ||
|
||
if ( file_exists( $this->ffFactory->getAbsoluteSkinDirectory() . DIRECTORY_SEPARATOR . $pageTemplate ) ) { | ||
$template = $pageTemplate; | ||
} | ||
|
||
return $this->ffFactory->getLayoutTemplate($template, $context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{% extends 'Base_Layout.html.twig' %} | ||
|
||
{% block page_identifier %}page-{$ page_id $}{% endblock %} | ||
|
||
{% block main %} | ||
<section> | ||
<div class="container clearfix"> | ||
<div class="ltcol"> | ||
| ||
</div> | ||
|
||
<div class="ctcol"> | ||
<div class="box partial rounded no-margin"> | ||
<div class="box-header container clearfix"> | ||
<span class="icon-hand-right f-left">{$ page_id|trans({}, 'pageTitles') $}</span> | ||
</div> | ||
|
||
<div class="box-section box-footer"> | ||
<div class="container clearfix sandboxedcontent {$ page_id $}"> | ||
{$ web_content("pages/#{page_id}") $} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="rtcol"> | ||
<div class="itz-logo"> | ||
<a href="{$ 'content_pages_itz_link' | trans | e ( 'html_attr' ) $}" target="_blank" title="{$ 'content_pages_itz_title' | trans | e ( 'html_attr' ) $}"> | ||
<img src="{$ 'content_pages_itz_logo' | trans | e ( 'html_attr' ) $}" alt="{$ 'content_pages_itz_title' | trans | e ( 'html_attr' ) $}"> | ||
</a> | ||
</div> | ||
|
||
{% if page_id == 'supporters' %} | ||
<div class="icon-ok-sign _icon-list-item last"> | ||
<p> | ||
<strong>Spenden auch Sie!</strong> | ||
</p> | ||
|
||
<p> | ||
Unterstützen Sie die Wikipedia und Freies Wissen mit Ihrer <a target="_blank" href="{$ path( '/', { piwik_campaign: 'spenden_wikimedia_benefactors', piwik_kwd: 'benefactors' } ) $}">Spende</a>. | ||
</p> | ||
</div> | ||
{% else %} | ||
<div class="icon-hand-right _icon-list-item last"> | ||
<p> | ||
<strong>Spenden</strong> | ||
</p> | ||
<p> | ||
<a href="{$ path( '/' ) $}" target="_blank">Zurück</a> zur Spendenseite | ||
</p> | ||
</div> | ||
{% endif %} | ||
</div> | ||
</div> | ||
</section> | ||
{% endblock %} |
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% extends 'page_layouts/base.html.twig' %} | ||
{% set page_works_without_js = false %} | ||
|
||
{% block scripts %} | ||
<script src="{$ basepath $}/skins/cat17/scripts/supporters.js"></script> | ||
{% endblock %} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% extends 'page_layouts/base.html.twig' %} | ||
|
||
{% block main %} | ||
<div class="test-block">Test</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters