Server-side Languages

Surreal generally works well with PHP and other server-side languages, but there are some caveats you should be aware of.

Metadata

Avoid using server-side code to populate metadata. Surreal expects these tags to be static, so values such as the ones shown below will be overwritten when publishing.

<!-- Don't do this -->
<title><?php echo $title; ?></title>
<meta name="description" content="<?php echo $content; ?>">

Content Regions

Surreal displays a copy of your rendered page in the editor, so it's not aware of any server-side code that may be used to generate each page. As a result, any server-side code that exists insidecontent region will be removed when publishing.

To prevent this, avoid putting PHP code or other server-side code inside your content regions.

<!-- Don't do this -->
<div id="my-content" class="cms-editable">
  <?php echo $content; ?>
</div>

HTML Attributes

When outside of a content region, you can use PHP to populate HTML attribute values. The code must be entirely within the attribute's quotes.

<!-- This is supported -->
<div class="<?php echo $myClass ?>">
  ...
</div>

However, avoid using PHP to conditionally attach attributes.

<!-- This is not supported -->
<div <?php echo $myClass === 'active' ? 'class="active"' : '' ?>>
  ...
</div>

This limitation exists because of the way our HTML parser handles server-side code embedded in HTML.