> For the complete documentation index, see [llms.txt](https://wplake.gitbook.io/advanced-views/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wplake.gitbook.io/advanced-views/layouts/code-fields/custom-template.md).

# Custom Layout template

Once you've defined the fields list in your [*Layout*](/advanced-views/getting-started/first-layout.md), Advanced Views **automatically** generates a default template for them. It recognizes each field type and produces the appropriate markup - for example, an `<img>` tag for an [Image field](/advanced-views/field-types/media/image-field.md), a loop for a [Gallery field](/advanced-views/field-types/media/gallery-field.md), and so on.

{% hint style="success" %}
By copying the **Default Template** into the **Custom Template** field, you are getting complete control over the markup.
{% endhint %}

Advanced Views eliminates the need to learn your field provider's documentation or manually retrieve field data. It automatically transforms raw database values into template-ready formats.&#x20;

For example, an image ID stored in the database is passed as a complete image object with properties such as `src`, `width`, and `height`.This lets you **focus on crafting the layout** instead of dealing with field types and meta retrieval.

{% hint style="info" %}
Layouts are composable, meaning one *Layout* can include another. \
*Layout* templates also support arbitrary logic, allowing you to perform operations such as combining field values, formatting output, or calling any WordPress function directly within the template.
{% endhint %}

## 1. How to customize *Layout* template

{% hint style="info" %}
Both *Default Template* and *Custom Template* fields are smart templates that use one of the [built-in template engines](/advanced-views/features/smart-templates.md).&#x20;
{% endhint %}

1. Go to **Edit** your *Layout.*
2. Switch to the *Template* tab.
3. **Select** the *Default Template* code and **copy it**.
4. Paste the code in the *Custom Template* field.
5. Edit the markup as needed.
6. Click on **Update** to save your *Layout*.

{% hint style="warning" %}
If you have added new fields in your *Layout*, remember to click **Update** to ensure that you have the latest template before editing.
{% endhint %}

## 2. How to display arbitrary fields

If you need to add arbitrary fields from a provider that is not supported by Advanced Views out of the box, you can add the [get\_post\_meta()](https://developer.wordpress.org/reference/functions/get_post_meta/) WordPress call into the template and display any meta value.

For vanilla PHP:

```php
<?= get_post_meta($_layout["object_id"], 'YOUR_FIELD_NAME'); ?>
```

For Blade:

```blade
{{ get_post_meta($_layout["object_id"], 'YOUR_FIELD_NAME') }}
```

For Twig, you have to load the field via the [Layout Controller](/advanced-views/layouts/code-fields/layout-controller.md#custom-variables-for-extra-data).

{% hint style="info" %}
Ensure you replace the field name with yours - you can consult your data vendor's docs. Alternatively, you can use any PHP function that your data vendor provides to fetch values.
{% endhint %}
