Reputation: 1238
I have base template with page title and Open Graph meta
base.html
<!DOCTYPE html>
<title>{% block title %}{% endblock %}</title>
<meta property="og:title" content="{% block og-title %}{% endblock %}">
In my child template i want to set both title
and og-title
to same value. I want use only templates, and avoid duplication of title value.
I can put og-title
block inside title
block to achieve this.
child.html
{% extends 'base.html' %}
{% block title %}{% block og-title %}{% endblock %}{% endblock %}
This works as i expect for Django 1.8.4. But the question is how long it will remain working solution? Is it a kind of dirty hack, that could stop working in feature?
Upvotes: 2
Views: 128
Reputation: 74
You can use django-capture-tag to capture title block value:
<title>{% capture as meta_title %}{% block title %}{% endblock %}{% endcapture %}</title>
<meta property="og:title" content="{{ meta_title }}">
Upvotes: -1