placeholder
はユーザ編集領域を定義するタグです。
使用例:
{% placeholder "article_content" %}
定義領域にはJSM7が用意したCMSパーツを設置できます。
CMSパーツには記事、画像、リンク、動画、地図等が用意されており、一旦パーツを設置するとダブルクリックによる編集が可能になります。
設置可能なパーツは予約された引数( placeholder名
)で制御され、1つまたは複数から選択します:
placeholder名 機能 article_content
全てのパーツを選択可能です。 banner_content
バナーパーツのみ設置可能です。 visual_content
画像パーツのみ設置可能です。
上記の他、各クライアント専用の placeholder名
を用意できます。
その場合は こちら までご連絡ください。
placeholder名
の後に or
を指定すると、placeholderにデフォルトで設定されるコンテンツを指定できます。
or
を指定した場合、デフォルトで表示するコンテンツの終わりに {% endplaceholder %}
を定義します:
{% placeholder "visual_content" or %}
<li><a href="#"><img src="/main_image_01.jpg" width="960" height="280" alt=""></a></li>
<li><a href="#"><img src="/main_image_02.jpg" width="940" height="280" alt=""></a></li>
<li><a href="#"><img src="/main_image_03.jpg" width="940" height="280" alt=""></a></li>
{% endplaceholder %}
placeholder名
の後に inherit
を指定すると、親ページの placeholder
を継承します:
{% placeholder "banner_content" inherit %}
継承する placeholder
が親ページに存在しなかった場合のエラー発生を防ぐため
inherit
の後に or
引数を併せて指定できます:
{% placeholder "original_content" inherit or %}親ページに"original_content"がありません{% endplaceholder %}
また、with
タグで placeholder
タグを囲むと placeholder
に値を渡せます。
以下は placeholder
の幅(width)を320pixcelに、高さ(height)を160pixcelに設定した例です:
{% with width=320 height=160 %}{% placeholder "banner_content" %}{% endwith %}
static_placeholder
タグは、ヘッダーやフッター、バナーなど複数のページで同じ内容のユーザ編集領域を提供するために使用します。
使用方法は placeholder
タグと同様です:
{% static_placeholder "footer" %}
{% static_placeholder "footer" or %}編集領域がありません{% endstatic_placeholder %}
警告
静的ユーザ編集可能領域は、編集してもページの編集履歴に残らず、やり直す/もう一度 の操作ができません。
show_placeholder
は他ページの placeholder
を参照します。
show_placeholder
タグを記述したページ内では参照したコンテンツを編集できません。
第1引数に placeholder名
、第2引数に参照ページを指定します:
# "footer_container_page"ページにある"footer"placeholderの情報を参照します。
{% show_placeholder "footer" "footer_container_page" %}
# request.current_page.parent_idが指すページにある"content"placeholderの情報を参照します。
{% show_placeholder "content" request.current_page.parent_id %}
# request.current_page.get_rootのページにある"teaser"placeholderの情報を参照します。
{% show_placeholder "teaser" request.current_page.get_root %}
参照先コンテンツが変更された場合、直ちに変更を反映させるにはキャッシュ利用なしの
show_uncached_placeholder
タグを使用できます。
page_url
はサイト内の任意のページのURLを取得するタグです。
第1引数にサイト内ページURLに相当する変数を指定します:
<a href="{% page_url "help" %}">Help page</a>
<a href="{% page_url request.current_page.parent %}">親ページへ</a>
また、第2引数に as
を指定すると page_url
の戻り値に別名を設定できます。
可読性を高めたり、同じテンプレートファイル内で何度も利用するために設定します。
使用例:
{% page_url request.current_page.parent as parent_url %}
<a href="{{ parent_url }}">親ページヘ</a>
page_attribute
は任意のページの属性を取得するためのタグです。
第1引数には次の属性名を指定します。
"title"
, "menu_title"
, "page_title"
,
"slug"
, "meta_description"
, "changed_date"
,
"changed_by"
例:
{% page_attribute "page_title" %}
第2引数に他ページを指定すると、他ページの属性値を取得します。
例:
{% page_attribute "page_title" "my_page_reverse_id" %}
{% page_attribute "page_title" request.current_page.parent_id %}
{% page_attribute "slug" request.current_page.get_root %}
また、page_urlと同様に as
で戻り値を変数で取得します。
例:
{% page_attribute "page_title" as title %}
<a href="/mypage/">{{ title }}</a>
{% page_attribute "page_title" "my_page_reverse_id" as title %}
<a href="/mypage/">{{ title }}</a>
現在のページのパンくずリストを生成します。引数は全てオプションで、省略可能です。
第1引数の start_level
(default=0) は、どの階層から表示するかを示します。
第2引数の template
(default=menu/breadcrumb.html) は、テンプレートファイルを指定します。
第3引数の only_visible
(default=True)は、True(=1)であればナビゲーションメニューに表示されるページのみ表示します。
Example:
{% show_breadcrumb %}
2階層目以降を表示し、テンプレートを変更した例:
{% show_breadcrumb 2 "myapp/breadcrumb.html" %}
全てのページをパンくずリストで生成する例:
{% show_breadcrumb 0 "menu/breadcrumb.html" 0 %}
外部システムなどで作成したページは(JSM7で未管理のページ)は、パンくずリストを生成しません。 この場合、現在のページに適用されたテンプレート(例:base.html)のパンくずリストブロックを別のテンプレート(例:override.html)で上書きして対応します。
base.html例:
<ul>
{% block breadcrumb %}
{% show_breadcrumb %}
{% endblock %}
<ul>
override.html例:
{% block breadcrumb %}
<li><a href="/">home</a></li>
<li>My current page</li>
{% endblock %}
現在のページに対する別言語のページURLを取得します:
{% page_language_url de %}
{% page_language_url fr %}
{% page_language_url en %}
addtoblock
で記述したHTMTLを render_block
を記載した位置に置換します。
render_block
は、 {% render_block <name> %}
の様に使い、
addtoblock
は {% addtoblock <name> [strip] %}...{% endaddtoblock %}
の様に使います。
strip
引数を使った場合は、HTML前後の空白文字を削除します。
使用例:
{% load cms_tags, menu_tags, sekizai_tags %}
<html>
<head>
{% render_block "css" %}
</head>
<body>
Your content comes here.
Maybe you want to throw in some css:
{% addtoblock "css" %}
<link href="/media/css/stylesheet.css" media="screen" rel="stylesheet" type="text/css" />
{% endaddtoblock %}
Some more content here.
{% addtoblock "js" %}
<script type="text/javascript">
alert("Hello django-sekizai");
</script>
{% endaddtoblock %}
And even more content.
{% render_block "js" %}
<body>
</html>
上記のHTMLは次のようにレンダリングされます:
<html>
<head>
<link href="/media/css/stylesheet.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
Your content comes here.
Maybe you want to throw in some css:
Some more content here.
And even more content.
<script type="text/javascript">
alert("Hello django-sekizai");
</script>
<body>
</html>
※
render_block
は、多くのテンプレートから継承されるベーステンプレート(base.html)に記載することを推奨します。
警告
{% render_block %}
を、他のブロックタグの中に定義しないで下さい。
{% addtoblock %}
を定義したテンプレートを継承する場合には、必ず、{% block %}...{% endblock %}タグの中に {% addtoblock %}
を記述して下さい。
任意のページのリンクを抽出して表示します。 6つの引数を指定でき、第1と第2引数とが必須です。
第1引数の placeholder_name
にはリンクの抽出対象となるplaceholder_nameを指定します。
第2引数の page_lookup
にはページの詳細設定で指定するページIDを指定します。
これがリンク抽出ページの指定です。
第3引数の limit(default=5)
は抽出するリンクの上限を指定します。
第4引数の template(default=topics.html)
は表示用のテンプレートを指定します。
第5引数の lang(default=None)
はja,enなどの言語を指定します。通常は指定不要です。
第6引数の site(default=None)
は他のサイトのページを指定します。通常は指定不要です。
以下は、topicsというページIDを持つページのarticle_content内にあるリンクを抽出します:
{% show_topics_list "article_content" "topics" %}