Purpose

In Wonderful Relations, Templates serve as the primary structural unit for rendering HTML-based objects like dashboards, and data-driven elements like data-tables. They provide a flexible and reusable framework for building interactive front-end components, admin pages, and dynamic content blocks.

Templates act as wrappers for rendered HTML objects, organizing elements such as dashboards, DataTables, and child templates. They are the top-level container in the system, allowing hierarchical nesting of templates within templates. The visibility and access control of templates can be managed via user groups, ensuring that only authorized users can view and interact with them.

Unlike static web pages, templates in Wonderful Relations can be dynamically filled with data, enabling structured output using queries and database results. They can be embedded into WordPress pages via shortcodes or directly integrated into the backend through PHP hooks.

Visual Example

Config:

Result:

Integration & Usage

Templates in Wonderful Relations can be used in various ways

Embedding Templates via Shortcodes

Templates can be embedded directly into WordPress pages or posts using shortcodes:

[wr_template identifier="my_template_identifier"]

This allows dynamic content to be displayed in WordPress without manual HTML integration.

Integrating Templates in PHP (e.g., Plugin Code)

Templates can also be rendered programmatically within PHP-based applications:

echo do_shortcode("[wr_template identifier=my_template_identifier]");

This method enables developers to insert templates dynamically into their code, providing a seamless way to integrate data-driven content.

Using Templates in the WordPress Backend

Templates can also be used for building backend pages within the WordPress admin panel:

class Menu {
    public function __construct() {
        $this->load_hooks();
    }
 
    public function load_hooks(): void {
        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
    }
 
    public function admin_menu(): void {
        add_menu_page(
            "YourPlugin",
            "YourPlugin",
            'manage_options',
            'your_plugin',
            array( $this, 'page_settings' ),
        );
    }
 
    public function page_settings(): void {
        echo do_shortcode("[wr_template identifier=your_plugin_dashboard]");
    }
}
 
new Menu();

In this example, a template is directly embedded into an admin page using WordPress’ add_menu_page function.

Parameters

A Template consists of the following key parameters:

Title

The display name of the template.

Project

Associates the template with a specific Wonderful Relations project.

Identifier

A unique key used for programmatic access and embedding.

Description

A brief explanation of the template’s purpose.

Conclusion

Templates in Wonderful Relations provide a scalable, dynamic, and structured way to manage content, both in the front-end and back-end of WordPress.

With support for:

  • Shortcodes for WordPress integration
  • PHP embedding for programmatic usage
  • Nesting capabilities for structured layouts
  • Group-based access control for visibility management

Templates act as the foundation for dynamically generated content, making it easy to build interactive, data-driven dashboards and pages without excessive complexity. 🚀