Last active
June 26, 2020 03:24
-
-
Save camoa/7686e80ae494f19b3c3cfde1e087ca7b to your computer and use it in GitHub Desktop.
D728 Task-23 Pre-process output provided by other modules
This file contains hidden or 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
lotus-js: | |
version: 1.x | |
js: | |
js/lotus.js: {} | |
dependencies: | |
- core/jquery |
This file contains hidden or 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
/** | |
* Implements hook_preprocess_page() | |
* $variables contains all variables used for the template. | |
* $hook should be ‘page’ in this case. | |
**/ | |
Function lotus_preprocess_page(&$variables, $hook) { | |
// Rendering a table inside the template | |
// Using a render array is the best practice here - Twigg will render it correctly. | |
$variables['table'] = array( | |
'#theme' => 'table', | |
'#header' => $header, | |
'#rows' => $rows, | |
); | |
//Add a JS library | |
$variables['#attached']['library'][] = 'lotus/lotus-js'; | |
} | |
* Implements hook_theme_suggestions_page_alter() | |
* $variables contains all variables used for the template. | |
* $suggestions will contain the current suggestions for the hook | |
* ‘page’ in this case. | |
**/ | |
Function lotus_theme_suggestions_page_alter(array &$suggestions, array $variables) { | |
// Add a new suggestion for a page template | |
// This allows us to use a template name page--lotus.tpl.php | |
$suggestions[] = 'page__lotus'; | |
} |
This file contains hidden or 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
// Add classes in templates is a preferred way in Drupal 8 | |
{% | |
set classes = [ | |
'new-class', | |
] | |
%} | |
<div{{ attributes.addClass(classes) }}> | |
// Print the table variable | |
<div class=’table’> | |
{{ table }} | |
</div> | |
//Print the text and link to create new content | |
<p>{{ 'To create some content <a href="@create-content">click here</a>.'|t({'@create-content': url('admin/structure/types/add')}) }}</p> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment