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

Twig templates as theme templates #43

Open
aroberts91 opened this issue May 16, 2024 · 4 comments
Open

Twig templates as theme templates #43

aroberts91 opened this issue May 16, 2024 · 4 comments

Comments

@aroberts91
Copy link

Is there a way to use twig files as themes which a user can select when editing a page in wp admin? Or does this still need to be handled by a Wordpress theme?

I would like to give the user the ability to choose between a number of templates but still have access to twigs templating functionality

@aroberts91
Copy link
Author

aroberts91 commented May 16, 2024

Just to further this. I have tried to create a custom template in wordpress.yaml in the hopes this could be routed to a twig file, or I could find a way to do it:

wordpress.yaml

  template:
    page:
      test_template: 'Test Template'

But trying to set this template when editing a page throws the error:

"status": 400,
       "params": {
           "template": "template is not one of ."
       },
       "details": {
           "template": {
               "code": "rest_invalid_param",
               "message": "template is not one of .",
               "data": null
           }
       }

@jerome-barbato
Copy link
Member

jerome-barbato commented May 31, 2024

Hi @aroberts91 nice catch, I'm working on a fix right now. I keep you up to date.

@jerome-barbato
Copy link
Member

jerome-barbato commented May 31, 2024

@aroberts91 the issue was in the wp-steroids plugin. I have published a new version with a fix.
Please do a composer update to update it.

Here is a code sample on how to use it. In your action, you need to get the template from the post object:

public function pageAction(Post $post)
{
    $template = $post->getTemplate()?:'page';

    return $this->render('pages/'.$template.'.html.twig', [
         'post'=>$post
    ]);
}

Let me know :)

@aroberts91
Copy link
Author

@jerome-barbato Thanks! I'll give it a try and let you know asap

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

No branches or pull requests

2 participants