Skip to content

Commit 79bfb4b

Browse files
committed
medEng theme structure
1 parent 94af44e commit 79bfb4b

5 files changed

+143
-2
lines changed

_posts/2023-05-20-mediaengagement-technical-docs.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,15 @@ This will save you storage on your machine because all images will be fetched fr
8181
}
8282
```
8383

84-
2. Open `siteRoot/conf/nginx/site.conf.hbs` in your editor and add the below snippet below the "{{/unless}}" line in the `# WordPress Rules`:
84+
2. Open `siteRoot/conf/nginx/site.conf.hbs` in your editor and add the below snippet below the
85+
86+
<pre>
87+
{% raw %}
88+
{{unless}}
89+
{% endraw %}
90+
</pre>
91+
92+
line in the `# WordPress Rules`:
8593

8694
```
8795
include uploads-proxy.conf;

_posts/2023-05-21-mediaengagement.md

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ For more in depth detail see [Technical Docs - First Day on the Job](/mediaengag
3838

3939
5. **Explore WordPress**: If you’re new to WordPress, take some time to explore the admin panel on your local environment. Feel free to experiment—any issues can be reverted with `git reset --hard origin/master`. Commit frequently and work in new branches.
4040

41+
- [WordPress Developer docs - creating custom pages](https://developer.wordpress.org/themes/template-files-section/page-template-files/)
42+
4143
##### _Pro Tips:_
4244

4345
- Changes to the frontend are typically located in the templates or SCSS files under the `assets` folder.
@@ -104,7 +106,7 @@ location ~ ^/wp-content/uploads/(.*) {
104106
</li>
105107

106108
<li>
107-
<p>Open <code>siteRoot/conf/nginx/site.conf.hbs</code> in your editor and add the below snippet below the <code>{{</code><code>/unless}}</code> line in the `# WordPress Rules`:</p>
109+
<p>Open <code>siteRoot/conf/nginx/site.conf.hbs</code> in your editor and add the below snippet below the <code>{{unless}}</code> line in the `# WordPress Rules`:</p>
108110

109111
<pre class="highlight"><code>
110112
include uploads-proxy.conf;
@@ -265,6 +267,137 @@ Engage uses the **Timber** framework and **Twig** templating engine. Familiarize
265267
- [Timber Documentation](https://timber.github.io/docs/v2/)
266268
- [Twig Documentation](https://twig.symfony.com/doc/3.x/intro.html)
267269

270+
### Understanding a custom page template
271+
272+
Check out the existing page, Solidarity Journalisim, setup:
273+
274+
- Base file: page-solidarity-journalism.php renders the page-solidarity-journalism.twig markup:
275+
```php
276+
Timber::render(['page-solidarity-journalism.twig'], $context, ENGAGE_PAGE_CACHE_TIME);
277+
```
278+
279+
- .twig file: `templates/page-solidarity-journalism.twig` holds the markup/html for the page template.
280+
281+
- In this file you will also see `include` blocks where other .twig partials are included:
282+
283+
<pre>
284+
{% raw %}
285+
{% include "partial/tile.twig" with { 'tile': post } %}
286+
{% endraw %}
287+
</pre>
288+
289+
![templates](../assets/img/templates.jpg)
290+
291+
The base `page-solidarity-journalisim.php` file renders the `page-solidarity-journalism.twig` file.
292+
293+
`page-solidarity-journalisim.php` code:
294+
295+
```php
296+
<?php
297+
298+
/**
299+
* Template Name: Solidarity Journalism
300+
* Description: A Page Template for Solidarity Journalism
301+
*/
302+
303+
$context = Timber::context();
304+
$post = $context['post'];
305+
306+
// get newsroom resource posts from the relationship field
307+
$resource_posts = get_field('resource_posts');
308+
$context['resource_posts'] = $resource_posts;
309+
// END newsroom resource posts
310+
311+
Timber::render(['page-solidarity-journalism.twig'], $context, ENGAGE_PAGE_CACHE_TIME); // render of the .twig file
312+
```
313+
314+
The `Template Name: Solidarity Journalism` is required for WordPress to understand this file is a page template.
315+
316+
#### Create a sample page template
317+
318+
You can create a quick sample on your local installation to test. Just copy the `page-solidarity-journalism.php` file code into a new `page-sample.php`
319+
320+
Change `page-sample.php` from:
321+
322+
```php
323+
<?php
324+
325+
/**
326+
* Template Name: Solidarity Journalism
327+
* Description: A Page Template for Solidarity Journalism
328+
*/
329+
330+
$context = Timber::context();
331+
$post = $context['post'];
332+
333+
// get newsroom resource posts from the relationship field
334+
$resource_posts = get_field('resource_posts');
335+
$context['resource_posts'] = $resource_posts;
336+
// END newsroom resource posts
337+
338+
Timber::render(['page-solidarity-journalism.twig'], $context, ENGAGE_PAGE_CACHE_TIME);
339+
```
340+
341+
to:
342+
343+
```php
344+
<?php
345+
346+
/**
347+
* Template Name: Sample
348+
* Description: A Page Template for Sample
349+
*/
350+
351+
$context = Timber::context();
352+
$post = $context['post'];
353+
354+
// get newsroom resource posts from the relationship field
355+
$resource_posts = get_field('resource_posts');
356+
$context['resource_posts'] = $resource_posts;
357+
// END newsroom resource posts
358+
359+
Timber::render(['page-sample.twig'], $context, ENGAGE_PAGE_CACHE_TIME);
360+
```
361+
362+
then you create a new `templates/page-sample.twig` file and add simple HTML:
363+
```html
364+
<div class="sample-page">
365+
<h1>Sample test</h1>
366+
</div>
367+
```
368+
369+
now when you go to WP Admin and add a new page you should see "Sample" in the Page attributes > Template dropdown.
370+
371+
![sample-page-template](../assets/img/sample-page-template.png)
372+
373+
#### PHP providing the data to the Twig files
374+
375+
Referring back to the `page-solidarity-journalism.php` file, this code:
376+
377+
```php
378+
$resource_posts = get_field('resource_posts');
379+
$context['resource_posts'] = $resource_posts;
380+
```
381+
382+
... is where the `resource_posts` data from Advanced Custom Fields(ACF) is assigned to a variable and adds it to the page `$context`.
383+
384+
**It is highly suggested to check out the [Timber Context Docs](https://timber.github.io/docs/v2/guides/context/).**
385+
386+
Getting into the fine details now....
387+
388+
```php
389+
get_field()
390+
```
391+
392+
this is the ACF's function to pull data. In WP Admin sidebar check out the field group ACF > Solidarity Journalism.
393+
`resource_posts` Relationship type field corresponds to the `get_field('resource_posts')`.
394+
395+
> How are the ACF fields assigned to a page/post template?
396+
397+
In the field group look for "Settings". In this example the "Location Rules" are set to the post template "Soldiarity Journalisim"
398+
399+
![acf settings](../assets/img/acf-settings.png)
400+
268401
---
269402

270403
## Plugins

assets/img/acf-settings.png

111 KB
Loading

assets/img/sample-page-template.png

113 KB
Loading

assets/img/templates.jpg

316 KB
Loading

0 commit comments

Comments
 (0)