Title: Gutenberg: Checking current template type?
Last modified: August 19, 2024

---

# Gutenberg: Checking current template type?

 *  [oguruma](https://wordpress.org/support/users/oguruma/)
 * (@oguruma)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/gutenberg-checking-current-template-type/)
 * I am building a custom Gutenberg block to display image galleries.
 * I need a way to check in the Gutenberg editor what the current template/Post 
   type that the the user is editing.
 * I have a setting called sourceFromCurrent which tells the block to get the images
   that will be displayed in the gallery from a meta field associated with that 
   Post Type.
 * Of course, for this to work and not cause confusion, I’ll want to hide that setting
   if the user is not editing a template. For instance, if the user is editing a
   post (not a post** single** template), I don’t want them to be able to select
   the sourceFromCurrent option, however if they are editing a Single Post, Page,
   etc. I do want to enable that setting.
 * Is it possible to get the currently-being-edited Template?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Brian Alexander](https://wordpress.org/support/users/ironprogrammer/)
 * (@ironprogrammer)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/gutenberg-checking-current-template-type/#post-17965546)
 * Hi, [@oguruma](https://wordpress.org/support/users/oguruma/) 👋🏻 Would checking
   for `[wp.data.select('core/edit-site')](https://developer.wordpress.org/block-editor/reference-guides/data/data-core-edit-site/)`
   provide enough context here? I.e. “Is the user in the site editor?” versus editing
   a post/page directly.
 *  Thread Starter [oguruma](https://wordpress.org/support/users/oguruma/)
 * (@oguruma)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/gutenberg-checking-current-template-type/#post-17972627)
 * [@ironprogrammer](https://wordpress.org/support/users/ironprogrammer/) Thanks
   for the input. I don’t think that would work because I need the context of the
   currently-being-edited post type. For example, a user might a have meta field
   called post_gallery for the Post post type, and a separate meta field called 
   image_gallery for the Projects post type.
 *  [Brian Alexander](https://wordpress.org/support/users/ironprogrammer/)
 * (@ironprogrammer)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/gutenberg-checking-current-template-type/#post-17997923)
 * Gotcha — The template can be accessed from that same `core/edit-site` store, 
   and checking the post ID will return the template’s slug (in format `theme-slug//
   template-name`). For instance, with the TT4 theme:
 *     ```wp-block-code
       > wp.data.select('core/edit-site').getEditedPostId();// Blog Home template"twentytwentyfour//home"// Single Posts template"twentytwentyfour//single"// Pages template"twentytwentyfour//page"
       ```
   
 * Does that help?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Gutenberg: Checking current template type?’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 2 participants
 * Last reply from: [Brian Alexander](https://wordpress.org/support/users/ironprogrammer/)
 * Last activity: [1 year, 9 months ago](https://wordpress.org/support/topic/gutenberg-checking-current-template-type/#post-17997923)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
