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

Add new locator schema templates:// #3059

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

NicoHood
Copy link
Contributor

@NicoHood NicoHood commented Nov 9, 2020

@rhukster
Copy link
Member

rhukster commented Nov 9, 2020

what is the compelling reason for this?

@NicoHood
Copy link
Contributor Author

NicoHood commented Nov 9, 2020

The reason for adding the docs or adding templates://?

  1. It is used in multiple plugins but the parameters are not explained anywhere.

  2. I want to create a plugin that adds structured data (json-ld) to the page. It processes the page.header and if it finds an entry it searches a corresponding template.

For example:

structured_data:
    local_business:
        name: 'Pizza Restaurant'
        address: [...]
// Check if a template exists for the given data
$template = 'structured-data/json-ld/' . $key . '/' . $key . '.json.twig';
if ($locator->findResource('templates://' . $template, true, false) === false) {
    continue;
}
$this->grav['twig']->processTemplate($template);
[...]

@mahagr
Copy link
Member

mahagr commented Dec 10, 2020

It won't work. The reason is that twig isn't using a stream and paths can be added later, too.

@NicoHood
Copy link
Contributor Author

I dont understand, it works for me. And the event to add path is run first, so all templates should be in place. But I am no expert here, however I've need a solution to lookup the templates from a plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants