Skip to content

Commit

Permalink
Merge pull request #283 from drupalprojects/8.x-5.x--page-tpl
Browse files Browse the repository at this point in the history
adding page template and preprocess for page assets.
  • Loading branch information
John Ouellet committed Jun 10, 2016
2 parents 33f53c1 + 94ef737 commit ebb1f96
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 16 deletions.
5 changes: 0 additions & 5 deletions src/Framework/KalathemeBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ class KalathemeBootstrap extends KalathemeBase implements KalathemePagePreproces
*/
public function preprocessHtml(array &$variables) {}

/**
* {@inheritdoc}
*/
public function preprocessPage(array &$variables) {}

/**
* {@inheritdoc}
*/
Expand Down
31 changes: 31 additions & 0 deletions src/Theme/KalathemeBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Drupal\kalatheme\Theme;

use Drupal\block\Entity\Block;

/**
* Defines base class to be used with all Framework Classes.
Expand Down Expand Up @@ -100,6 +101,36 @@ public function libraryBuild() {
return $libraries;
}

/**
* Return altered variables for the page template.
*
* @return array
* An associative array of the same format as returned by
* template_preprocess_page().
*
* @see template_preprocess_page
*/
public function preprocessPage(array &$variables) {
// Get active theme
$theme = \Drupal::theme()->getActiveTheme()->getName();

// Load all the blocks to parse through.
$blocks = Block::loadMultiple();
// We are adding all the blocks so we can.
// achieve for the One content region setup.
foreach ($blocks as $key => $block) {
$check = strstr($key, '_', TRUE);
// Check is the block name matches the theme.
if ($check == $theme) {
$name = ltrim(strstr($key, '_'), '_');
// Load the block as a var to use in the page.html.twig.
$variables[$name] = \Drupal::entityManager()
->getViewBuilder('block')
->view($block);
}
}
}

/**
* Return altered attachments to a page before it is rendered.
*
Expand Down
11 changes: 0 additions & 11 deletions src/Theme/Preprocess/KalathemePagePreprocessInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,4 @@ interface KalathemePagePreprocessInterface {
* @see template_preprocess_html
*/
public function preprocessHtml(array &$variables);

/**
* Return altered variables for the page template.
*
* @return array
* An associative array of the same format as returned by
* template_preprocess_page().
*
* @see template_preprocess_page
*/
public function preprocessPage(array &$variables);
}
88 changes: 88 additions & 0 deletions templates/system/page.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{#
/**
* @file
* Theme override to display a single page.
*
* The doctype, html, head and body tags are not in this template. Instead they
* can be found in the html.html.twig template in this directory.
*
* Available variables:
*
* General utility variables:
* - base_path: The base URL path of the Drupal installation. Will usually be
* "/" unless you have installed Drupal in a sub-directory.
* - is_front: A flag indicating if the current page is the front page.
* - logged_in: A flag indicating if the user is registered and signed in.
* - is_admin: A flag indicating if the user has permission to access
* administration pages.
*
* Site identity:
* - front_page: The URL of the front page. Use this instead of base_path when
* linking to the front page. This includes the language domain or prefix.
*
* Page content (in order of occurrence in the default page.html.twig):
* - messages: Status and error messages. Should be displayed prominently.
* - node: Fully loaded node, if there is an automatically-loaded node
* associated with the page and the node ID is the second argument in the
* page's path (e.g. node/12345 and node/12345/revisions, but not
* comment/reply/12345).
*
* Regions:
* - page.content: The main content of the current page.
*
* @see template_preprocess_page()
* @see html.html.twig
*/
#}

{%
set navbar_classes = [
'navbar',
theme.settings.navbar_inverse ? 'navbar-inverse' : 'navbar-default',
theme.settings.navbar_position ? 'navbar-' ~ theme.settings.navbar_position|clean_class : '',
]
%}
<header{{ navbar_attributes.addClass(navbar_classes) }} id="navbar" role="banner">
<div class="container">
<div class="navbar-header">
{{ branding }}

<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">{{ 'Toggle navigation'|t }}</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>

<div class="navbar-collapse collapse">
<nav role="navigation">
{{ main_menu }}
</nav>
</div>
</div>
</header>

<main id="main" class="clearfix js-quickedit-main-content" role="main">

<section class="column container">

{{ breadcrumb }}
<a id="main-content"></a>

{{ messages }}
{{ help }}

{% if action_links %}
<ul class="action-links">{{ action_links }}</ul>
{% endif %}
</section>

<section class="container main-container">
{{ page.content }}
</section>

</main>

<footer></footer>

0 comments on commit ebb1f96

Please sign in to comment.