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 inside a content 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 ?>">
<p>Welcome to our website.</p>
</div>
However, avoid using PHP to conditionally attach attributes.
<!-- This is not supported -->
<div <?php echo $myClass === 'active' ? 'class="active"' : '' ?>>
<p>Welcome to our website.</p>
</div>
This limitation exists because of the way our HTML parser handles server-side code embedded in HTML.
Template tags
Outside of content regions, PHP (<?php ?>), ASP (<% %>), and Razor
(@{ }) code is protected when publishing. Template tags such as {{ }} and
{% %} aren't protected, so they may not survive publishing. Avoid them in pages you edit
with Surreal.