Run prettier on all *.md files

```
prettier '{app,source}/**/**.md' --write
```
This commit is contained in:
Oliver Davies 2020-03-08 17:52:59 +00:00
parent a3ceeaf0f3
commit 85a10c545b
170 changed files with 5127 additions and 2282 deletions

View file

@ -2,14 +2,24 @@
title: Adding Custom Theme Templates in Drupal 7
date: 2012-04-19
excerpt: >
Today, I had a situation where I was displaying a list of teasers for news article nodes. The article content type had several different fields assigned to it, including main and thumbnail images. In this case, I wanted to have different output and fields displayed when a teaser was displayed compared to when a complete node was displayed.
Today, I had a situation where I was displaying a list of teasers for news
article nodes. The article content type had several different fields assigned
to it, including main and thumbnail images. In this case, I wanted to have
different output and fields displayed when a teaser was displayed compared to
when a complete node was displayed.
tags:
- drupal-planet
- drupal
---
Today, I had a situation where I was displaying a list of teasers for news article nodes. The article content type had several different fields assigned to it, including main and thumbnail images. In this case, I wanted to have different output and fields displayed when a teaser was displayed compared to when a complete node was displayed.
I have previously seen it done this way by adding this into in a node.tpl.php file:
Today, I had a situation where I was displaying a list of teasers for news
article nodes. The article content type had several different fields assigned to
it, including main and thumbnail images. In this case, I wanted to have
different output and fields displayed when a teaser was displayed compared to
when a complete node was displayed.
I have previously seen it done this way by adding this into in a node.tpl.php
file:
```language-php
if ($teaser) {
@ -20,9 +30,15 @@ else {
}
```
However, I decided to do something different and create a separate template file just for teasers. This is done using the hook_preprocess_HOOK function that I can add into my theme's template.php file.
However, I decided to do something different and create a separate template file
just for teasers. This is done using the hook_preprocess_HOOK function that I
can add into my theme's template.php file.
The function requires the node variables as an argument - one of which is theme_hook_suggestions. This is an array of suggested template files that Drupal looks for and attempts to use when displaying a node, and this is where I'll be adding a new suggestion for my teaser-specific template. Using the `debug()` function, I can easily see what's already there.
The function requires the node variables as an argument - one of which is
theme_hook_suggestions. This is an array of suggested template files that Drupal
looks for and attempts to use when displaying a node, and this is where I'll be
adding a new suggestion for my teaser-specific template. Using the `debug()`
function, I can easily see what's already there.
```language-php
array (
@ -41,7 +57,7 @@ So, within my theme's template.php file:
*/
function mytheme_preprocess_node(&$variables) {
$node = $variables['node'];
if ($variables['teaser']) {
// Add a new item into the theme_hook_suggestions array.
$variables['theme_hook_suggestions'][] = 'node__' . $node->type . '_teaser';
@ -61,4 +77,8 @@ array (
)
```
Now, within my theme I can create a new node--article-teaser.tpl.php template file and this will get called instead of the node--article.tpl.php when a teaser is loaded. As I'm not specifying the node type specifically and using the dynamic <em>$node->type</em> value within my suggestion, this will also apply for all other content types on my site and not just news articles.
Now, within my theme I can create a new node--article-teaser.tpl.php template
file and this will get called instead of the node--article.tpl.php when a teaser
is loaded. As I'm not specifying the node type specifically and using the
dynamic <em>\$node->type</em> value within my suggestion, this will also apply
for all other content types on my site and not just news articles.