or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.mdmenus.mdpages.mdpermissions.mdplugins.mdtemplates.mdutilities.md

templates.mddocs/

0

# Template Integration

1

2

Django CMS provides comprehensive template tag functionality for rendering CMS content in Django templates, including placeholder rendering, page attributes, navigation menus, and powerful inline editing capabilities.

3

4

## Capabilities

5

6

### Core Content Rendering

7

8

Essential template tags for rendering CMS content with placeholder support and inheritance.

9

10

```python { .api }

11

# Template tag usage (in Django templates)

12

{% placeholder "slot_name" %}

13

{% placeholder "slot_name" inherit %}

14

{% placeholder "slot_name" inherit or %}

15

<div>Fallback content when placeholder is empty</div>

16

{% endplaceholder %}

17

18

{% static_placeholder "identifier" %}

19

{% static_placeholder "identifier" site %}

20

21

{% show_placeholder "identifier" %}

22

{% show_placeholder_by_id page_lookup "slot_name" %}

23

{% show_uncached_placeholder "identifier" %}

24

{% show_uncached_placeholder_by_id page_lookup "slot_name" %}

25

26

{% render_placeholder placeholder %}

27

{% render_placeholder placeholder language width %}

28

{% render_placeholder placeholder inherit=True %}

29

{% render_placeholder placeholder as content %}

30

31

{% render_uncached_placeholder placeholder_object %}

32

```

33

34

### Page and URL Management

35

36

Template tags for generating page URLs and accessing page attributes.

37

38

```python { .api }

39

# Page URL generation

40

{% page_url page_lookup %}

41

{% page_url page_lookup as url_var %}

42

{% page_url "page-reverse-id" %}

43

{% page_url page_object %}

44

{% page_id_url page_id %}

45

46

# Page attributes

47

{% page_attribute "title" %}

48

{% page_attribute "slug" %}

49

{% page_attribute "meta_description" %}

50

{% page_attribute "page_title" %}

51

{% page_attribute "menu_title" %}

52

{% page_attribute "changed_date" %}

53

{% page_attribute "changed_by" %}

54

{% page_attribute "title" as page_title %}

55

```

56

57

### Plugin Rendering

58

59

Template tags for rendering individual plugins and plugin-related functionality.

60

61

```python { .api }

62

# Plugin rendering

63

{% render_plugin plugin_instance %}

64

65

{% render_plugin_block plugin_instance %}

66

<div>Custom content linked to plugin editing</div>

67

{% endrender_plugin_block %}

68

69

{% render_extra_menu_items obj template %}

70

```

71

72

### Inline Editing System

73

74

Powerful template tags that enable inline editing by linking content to Django admin changeforms.

75

76

```python { .api }

77

# Model editing integration

78

{% render_model instance attribute %}

79

{% render_model instance attribute edit_fields %}

80

{% render_model instance attribute edit_fields language %}

81

{% render_model instance attribute edit_fields language filters %}

82

{% render_model instance attribute edit_fields language filters view_url %}

83

{% render_model instance attribute edit_fields language filters view_url view_method %}

84

{% render_model instance attribute as varname %}

85

86

{% render_model_icon instance %}

87

{% render_model_add model_class %}

88

89

{% render_model_block instance attribute %}

90

<h1>{{ instance.attribute }}</h1>

91

{% endrender_model_block %}

92

93

{% render_model_add_block model_class %}

94

<div class="add-button">Add New Item</div>

95

{% endrender_model_add_block %}

96

```

97

98

### CMS Integration

99

100

Template tags for CMS toolbar integration and admin functionality.

101

102

```python { .api }

103

# CMS toolbar and admin integration

104

{% cms_toolbar %}

105

106

{% cms_admin_url "viewname" %}

107

{% cms_admin_url "viewname" arg1 arg2 %}

108

{% cms_admin_url "viewname" as admin_url %}

109

```

110

111

## Usage Examples

112

113

### Basic Page Template

114

115

```html

116

{% load cms_tags %}

117

<!DOCTYPE html>

118

<html>

119

<head>

120

<title>{% page_attribute "page_title" %} | My Site</title>

121

<meta name="description" content="{% page_attribute "meta_description" %}">

122

</head>

123

<body>

124

{% cms_toolbar %}

125

126

<header>

127

<h1>{% page_attribute "title" %}</h1>

128

</header>

129

130

<main>

131

{% placeholder "content" %}

132

</main>

133

134

<aside>

135

{% placeholder "sidebar" inherit or %}

136

<div class="default-sidebar">

137

<h3>Default Sidebar Content</h3>

138

<p>This appears when sidebar is empty.</p>

139

</div>

140

{% endplaceholder %}

141

</aside>

142

143

<footer>

144

{% static_placeholder "footer" %}

145

</footer>

146

</body>

147

</html>

148

```

149

150

### Advanced Placeholder Usage

151

152

```html

153

{% load cms_tags %}

154

155

<!-- Basic placeholder -->

156

{% placeholder "hero" %}

157

158

<!-- Placeholder with inheritance from parent pages -->

159

{% placeholder "sidebar" inherit %}

160

161

<!-- Placeholder with fallback content -->

162

{% placeholder "banner" or %}

163

<div class="default-banner">

164

<h2>Welcome to our site!</h2>

165

</div>

166

{% endplaceholder %}

167

168

<!-- Render placeholder with size constraints -->

169

{% render_placeholder page.placeholders.content width=800 %}

170

171

<!-- Uncached placeholder for dynamic content -->

172

{% render_uncached_placeholder dynamic_placeholder %}

173

174

<!-- Static placeholder for site-wide content -->

175

{% static_placeholder "site_notice" %}

176

177

<!-- Site-specific static placeholder -->

178

{% static_placeholder "local_footer" site %}

179

```

180

181

### Navigation and URL Generation

182

183

```html

184

{% load cms_tags menu_tags %}

185

186

<!-- Page URL generation -->

187

<a href="{% page_url "about" %}">About Us</a>

188

<a href="{% page_url home_page %}">Home</a>

189

190

<!-- Store URL in variable -->

191

{% page_url "contact" as contact_url %}

192

<a href="{{ contact_url }}">Contact</a>

193

194

<!-- Navigation menu -->

195

{% show_menu 0 100 100 100 %}

196

197

<!-- Breadcrumb navigation -->

198

{% show_breadcrumb 0 "breadcrumb.html" %}

199

200

<!-- Submenu -->

201

{% show_sub_menu 1 %}

202

```

203

204

### Inline Editing Integration

205

206

```html

207

{% load cms_tags %}

208

209

<!-- Make model fields editable -->

210

<article>

211

<h1>{% render_model article "title" %}</h1>

212

<div class="meta">

213

Published: {% render_model article "pub_date" %}

214

By: {% render_model article "author" %}

215

</div>

216

<div class="content">

217

{% render_model article "content" %}

218

</div>

219

</article>

220

221

<!-- Block-level editing -->

222

{% render_model_block article "title" %}

223

<h1 class="special-title">{{ article.title }}</h1>

224

{% endrender_model_block %}

225

226

<!-- Add new model instances -->

227

{% render_model_add Article %}

228

229

<!-- Edit icons -->

230

<div class="admin-tools">

231

{% render_model_icon article %}

232

{% render_model_add Article %}

233

</div>

234

```

235

236

### Complex Template Integration

237

238

```html

239

{% load cms_tags menu_tags %}

240

241

<nav class="main-navigation">

242

{% show_menu 0 1 100 100 "menu/main_menu.html" %}

243

</nav>

244

245

<main class="content-area">

246

<!-- Main content with inheritance -->

247

{% placeholder "content" inherit %}

248

249

<!-- Conditional placeholders -->

250

{% if page.reverse_id == "homepage" %}

251

{% placeholder "hero_banner" %}

252

{% placeholder "features" %}

253

{% else %}

254

{% placeholder "page_header" %}

255

{% endif %}

256

257

<!-- Dynamic plugin rendering -->

258

{% for plugin in page.get_placeholders.content.get_plugins %}

259

{% render_plugin plugin %}

260

{% endfor %}

261

</main>

262

263

<aside class="sidebar">

264

<!-- Static content with fallback -->

265

{% static_placeholder "sidebar_content" or %}

266

{% placeholder "page_sidebar" inherit or %}

267

<div class="default-sidebar">

268

<h3>Related Pages</h3>

269

{% show_menu 1 100 0 1 "menu/sidebar_menu.html" %}

270

</div>

271

{% endplaceholder %}

272

{% endstatic_placeholder %}

273

</aside>

274

```

275

276

### Admin and Toolbar Integration

277

278

```html

279

{% load cms_tags %}

280

281

<!-- CMS toolbar (required for editing) -->

282

{% cms_toolbar %}

283

284

<!-- Admin URLs with language context -->

285

<div class="admin-links">

286

<a href="{% cms_admin_url "admin:cms_page_changelist" %}">

287

Manage Pages

288

</a>

289

290

{% cms_admin_url "admin:cms_page_add" as add_page_url %}

291

<a href="{{ add_page_url }}">Add Page</a>

292

</div>

293

294

<!-- Conditional admin content -->

295

{% if request.user.is_staff %}

296

<div class="admin-panel">

297

{% render_model current_page "title" %}

298

{% render_model_add PageContent %}

299

</div>

300

{% endif %}

301

```

302

303

## Types

304

305

```python { .api }

306

# Template context objects (available in templates)

307

class TemplateContext:

308

"""

309

Template context for CMS template tags.

310

311

Available variables:

312

- request: Current HTTP request

313

- current_page: Active CMS page

314

- cms_content_renderer: Content rendering engine

315

- cms_toolbar: CMS toolbar instance (when in preview mode)

316

"""

317

318

class PlaceholderContext:

319

"""

320

Context for placeholder rendering.

321

322

Variables:

323

- placeholder: Placeholder instance

324

- plugins: List of plugins in placeholder

325

- width: Requested width for responsive plugins

326

- language: Current language code

327

"""

328

```