Hey all, I’ve got the following EEX template for my layout (clearly just the base template lightly modified), the chief difference being that I’ve moved my favicon, Google Analytics and Google Fonts tags into partials to clean things up a bit:
<!-- app.html.eex -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=0.9">
<meta name="description" content="">
<meta name="author" content="">
<title>FunctionHaus</title>
<link rel="stylesheet" href="<%= static_path(@conn, "/css/app.css") %>">
<%= render LayoutView, "_fonts.html" %>
<%= render LayoutView, "_favicons.html" %>
<%= render LayoutView, "_google_analytics.html" %>
</head>
<body>
<!-- etc... -->
</body>
</html>
The issue that I’m having is that when those sub-templates (can I say “partials”?) are rendered, all of the whitespace at the beginning of the rendered lines is trimmed, and the resulting HTML isn’t whitespaced properly:
<!-- RENDERED TEMPLATE OUTPUT -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=0.9">
<meta name="description" content="">
<meta name="author" content="">
<title>FunctionHaus</title>
<link rel="stylesheet" href="/css/app.css">
<link href="https://fonts.googleapis.com/css?family=Lato:900i|Lato:400|Lato:700|Patua+One" rel="stylesheet">
<link rel="shortcut icon" type="image/png" href="/images/favicon.png"/>
<!-- <link rel="shortcut icon" type="image/png" href="http://mysite.com/images/favicon.png"/> -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-12345678910-1', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<!-- etc... -->
</body>
</html>
Is there a way to enforce whitespace in the template render from the point at which the template is rendered, rather than having to add the whitespace to the sub-template itself?
Thanks,
Mike