user6035846
user6035846

Reputation:

SilverStripe layout and templates

Given the code below

Test.ss (in Templates)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    Templates
    $Layout
</body>
</html>

Test.ss (in Layout)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Layout</title>
</head>
<body>
    Layout
</body>
</html>

Output in SilverStripe:

Templates Layout

My question is is SilverStripe stripping html tags in layout?

Upvotes: 0

Views: 190

Answers (1)

3dgoo
3dgoo

Reputation: 15794

No, SilverStripe does not strip out html tags from your layout templates. The html you have in your template will be printed as is.

So your example templates will result in the following html output:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    Templates
    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Layout</title>
</head>
<body>
    Layout
</body>
</html>
</body>
</html>

You can view this for yourself by viewing your page source. In chrome the URL would be view-source:http://your-website-url

Avoid having html, head and body tags in layout templates as this is taken care of in the main template.

Instead, your template/layouts/test.ss file should look like this:

    <p>Layout</p>

With your original template/test.ss this would give you an output of:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    Templates
    <p>Layout</p>
</body>
</html>

Upvotes: 1

Related Questions