Giter Site home page Giter Site logo

Comments (4)

johnstonphilip avatar johnstonphilip commented on August 20, 2024

@Bowriverstudio if I understand you right, you want to use something like this in your theme's html files to include template parts:

<!-- wp:template-part {"slug":"name-of-template-part-file-without-extension","theme":"your-theme-name"} /-->

This is how the index.html file in the parisienne theme includes its header:
https://github.com/WordPress/theme-experiments/blob/master/parisienne/block-templates/index.html#L2

from theme-experiments.

Bowriverstudio avatar Bowriverstudio commented on August 20, 2024

Hi John, thanks for the answer. I've got a custom post type in a plugin and want to include a template part that is not in the child theme folder. Does that make sense?

from theme-experiments.

johnstonphilip avatar johnstonphilip commented on August 20, 2024

I traced the code for template-part inclusion back to here:
https://github.com/WordPress/gutenberg/blob/21304f999b1cbcc53d8ad098d297a6e9cf049e69/packages/block-library/src/template-part/index.php#L33

It doesn't look like there's any handling there for template files that would exist outside of a theme, so the only way I can see to do that would be to programmatically insert a post with the post_type set to wp_template_part and the slug set to match what your theme is calling as the slug.

In this case it would be the word "header", but I guess you could call it whatever you want. For example:

<!-- wp:template-part {"slug":"slug-of-your-programmatically-created-template-part","theme":"your-theme-name"} /-->

from theme-experiments.

Bowriverstudio avatar Bowriverstudio commented on August 20, 2024

Thank you for your help John. I think I'll just include the code I'd normally put in a plugin, in the theme for now.

from theme-experiments.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.