Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to override templates #28

Merged
merged 5 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Contributing

## Running locally
Start local site with:

```shell
wp-env start
```

Change permalink structure:

```shell
wp-env run cli "wp rewrite structure '/%postname%'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty big thing to ask for. Why is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something I noticed is needed at the moment, so I documented it. There's an issue for it at #19, once that is fixed these instructions can be removed.

```

The site is now available at http://localhost:8888.
44 changes: 37 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,47 @@ function oidc_clients() {
}
```

## Development
Start local site with:
## Overriding templates
The pages provided by this plugin are rendered using templates. If you so wish, you can use your own templates instead of this plugins's [default templates](templates).

To do so, you should create an `openid-connect/` directory under your theme, containing only the templates you wish to override. For example, if you wanted to override `authenticate/main.php` and `authenticate/forbidden.php` you would create them under an `openid-connect/` directory in your theme:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused by the use of the directory authenticate/. It is not necessary when overriding the templates? Why do we have this subdirectory in the first place?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

authenticate is the page for which the templates are, i.e. the page with URI /openid-connect/authenticate/. So there is one subdirectory per page.

At the moment there is only one page, but there might be other pages in the future, for example a page where you remove previously granted consent. Each page would get its own subdirectory under templates/.

Starting with subdirectories since day one, even if there is only one page at the moment, allows us to not break backwards compatibility once (or if) we do introduce other pages. Because users can override these templates, moving them would break backwards compatibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the paths in the docs were wrong here, I fixed that in #33


```shell
wp-env start
wp-content/themes/my-theme/
│── openid-connect/
│──── main.php
└──── forbidden.php
```
psrpinto marked this conversation as resolved.
Show resolved Hide resolved

Change permalink structure:
If your theme is a child theme, this plugin will first look for templates under the child theme, and then in the parent theme. If it doesn't find a template, it will fall back to using the default template.

```shell
wp-env run cli "wp rewrite structure '/%postname%'"
### Data
Templates are passed a single `$data` variable containing the values necessary to render said template. For example, you can access the name of the OIDC client as follows:

```php
// wp-content/themes/my-theme/main.php

/** @var stdClass $data **/

/** @var string $client_name The OIDC client name */
$client_name = $data->client_name;
```

You can of course also call any other WordPress function, like you would in any other file in your theme.

### Partials
In your templates, you can include partial templates (aka partials) by calling `$data->templates->partial()`:

```php
// wp-content/themes/my-theme/main.php

/** @var stdClass $data **/

/** @var \OpenIDConnectServer\Templating\Templating $templates */
$templates = $data->templates;

// Renders the <form> in the 'authenticate/form.php' partial.
$templates->partial( 'authenticate/form' )
```

The site is now available at http://localhost:8888.
Partials are also passed the `$data` variable.