> For the complete documentation index, see [llms.txt](https://docs.yaycommerce.com/yaymail/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yaycommerce.com/yaymail/developer-zone/api/register-elements/render-element-content.md).

# Render Element content

Basic Structure<br>

The layout file should be a PHP template that renders your element's HTML. Here's the basic structure:

Important Notes

* Security:
  * Always use `defined('ABSPATH') || exit`;
  * Escape all output using appropriate functions
  * Sanitize all input data
* Styling:
  * Use `TemplateHelpers::get_style()` for consistent styling
  * Use `TemplateHelpers::get_spacing_value()` for padding/margin
  * Use `TemplateHelpers::get_font_family_value()` for fonts
* Content Processing:
  * Use `do_shortcode()` for shortcode processing
  * Use `yaymail_kses_post()` for HTML content
  * Use output buffering for complex HTML structures

<pre class="language-php"><code class="lang-php">&#x3C;?php

<strong>defined('ABSPATH') || exit;
</strong><strong>
</strong>use YayMail\Utils\TemplateHelpers;

if (empty($args['element'])) {
    return;
}

$element = $args['element'];
$data    = $element['data'];

// Define styles
$wrapper_style = TemplateHelpers::get_style( [
    'word-break'       => 'break-word',
    'background-color' => $data['background_color'] ?? '#fff',
    'padding'          => TemplateHelpers::get_spacing_value( $data['padding'] ?? [] ),
] );

$title_style = TemplateHelpers::get_style( [
    'text-align'    => yaymail_get_text_align(),
    'color'         => $data['title_color'] ?? 'inherit',
    'margin-bottom' => '10px',
    'font-size'     => '18px',
    'font-weight'   => 'bold',
    'font-family'   => TemplateHelpers::get_font_family_value( $data['font_family'] ?? 'inherit'),
] );

// Process content
$title = isset( $data['title'] ) ? do_shortcode( $data['title'] ) : '';
$content = isset( $data['rich_text'] ) ? do_shortcode( $data['rich_text'] ) : '';

// Build HTML
ob_start();
?>
&#x3C;div class="your-element">
    &#x3C;h2 style="&#x3C;?php echo esc_attr( $title_style ); ?>">
        &#x3C;?php echo yaymail_kses_post( $title ); ?>
    &#x3C;/h2>
    &#x3C;div class="content">
        &#x3C;?php echo yaymail_kses_post( $content ); ?>
    &#x3C;/div>
&#x3C;/div>
&#x3C;?php
$element_content = ob_get_clean();

// Wrap and output
TemplateHelpers::wrap_element_content( $element_content, $element, $wrapper_style );
</code></pre>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.yaycommerce.com/yaymail/developer-zone/api/register-elements/render-element-content.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
