Skip to content

Commit 9400115

Browse files
committed
feat(blog-detail): Enhance blog post template with image support and additional metadata
1 parent 461368f commit 9400115

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

examples/dotcms-symfony/src/Controller/CatchAllController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public function show(string $path = ''): Response
5858
'layout' => $pageAsset->layout ?? null,
5959
'page' => $pageAsset->page ?? null,
6060
'containers' => $pageAsset->containers ?? [],
61-
'navigation' => $navigation
61+
'navigation' => $navigation,
62+
'dotcms_host' => $_ENV['DOTCMS_HOST'] ?? 'https://demo.dotcms.com'
6263
]);
6364
} catch (HttpException $e) {
6465
// Map HTTP errors to appropriate Symfony exceptions

examples/dotcms-symfony/templates/blog-detail.html.twig

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
11
{% extends 'base.html.twig' %}
22

3-
{% block title %}{{ pageAsset.page.title|default('Blog Post') }}{% endblock %}
4-
53
{% block body %}
64
{% include 'dotcms/header.twig' %}
75

86
<div class="container">
97
<div class="row">
108
<div class="col-start-1 col-end-13">
119
<article>
12-
<h1>{{ pageAsset.page.title }}</h1>
13-
14-
{% if pageAsset.urlContentMap.blogContent is defined %}
15-
<div class="blog-content">
16-
{{ renderBlockEditorField(pageAsset.urlContentMap.blogContent) }}
17-
</div>
10+
{% if pageAsset.urlContentMap.image is defined %}
11+
{% set imageHtml %}
12+
<figure style="margin-bottom: 2rem">
13+
<img src="{{ dotcms_host }}/dA/{{ pageAsset.urlContentMap.identifier }}/image"
14+
alt="{{ pageAsset.urlContentMap.title|default('')|e('html_attr') }}"
15+
style="width:100%;max-height:500px;object-fit:cover;">
16+
</figure>
17+
{% endset %}
18+
{{ imageHtml|raw }}
1819
{% endif %}
20+
21+
<div style="max-width: 70ch; margin: 0 auto;">
22+
23+
<header>
24+
<h1>{{ pageAsset.urlContentMap.title }}</h1>
25+
{% if pageAsset.urlContentMap.publishDate is defined %}
26+
{% set publishDate = pageAsset.urlContentMap.publishDate // 1000 %}
27+
<time datetime="{{ publishDate|date('c') }}" class="blog-publish-date">
28+
Published on {{ publishDate|date('F j, Y') }}
29+
</time>
30+
{% endif %}
31+
</header>
32+
33+
<hr />
34+
35+
{% if pageAsset.urlContentMap.blogContent is defined %}
36+
<div class="blog-content">
37+
{{ renderBlockEditorField(pageAsset.urlContentMap.blogContent) }}
38+
</div>
39+
{% endif %}
40+
41+
</div>
1942
</article>
2043
</div>
2144
</div>

0 commit comments

Comments
 (0)