だから、このコードが入っているクラフトに付属の標準テンプレートシステムを使用しています:
{% block content %}
If you see me, you haven’t set your
{% verbatim %}{%
block content %}…{% endblock %}{% endverbatim %}
yet.
See Twig’s
Template Inheritance documentation for an explanation.
{% endblock %}
明らかに私はそれにIDを設定するために少し余分に追加しました。
今度は、ブロックコンテンツの中でページコンテンツが定義されているので、ブロックコンテンツの中でどのタイトルを使用するかだけを知っているので、内部テンプレートのタイトルをレイアウトテンプレートに戻してここに表示する方法を教えてください。
<title>{% if title is defined %}{{ title }} - {% endif %}{{ siteName }}</title>
現在のところ、常に良いサイト名は表示されません。
CraftCMSのルート/セクション情報からコンテンツセクションが取り上げるコンテンツとして取り込まれたページのタイトルからタイトルを取得する必要があります。
これはCraftで提供されるデフォルトのレイアウトなので、これを行う簡単な方法が必要です!
title変数がコンテンツテンプレート内で定義されていることを確認しましたが、コンテンツテンプレート内で設定した変数は_layoutテンプレートにアクセスできません。
関連するコードの余分なビットをheres:
レイアウト:
<title>{% if title is defined %}{{ title }} - {% endif %}{{ siteName }}</title>
コンテンツ:
{% for content in entries %}
{% set title = content.title %}
前もって感謝します!
レイアウト:
{# # Layout template # --------------- # # This template defines your site’s global layout. It can be # “extended” by other templates to fill in the gaps. # # See Twig’s Template Inheritance documentation for more details: # http://twig.sensiolabs.org/doc/templates.html#template-inheritance #} {% set title3 = "test" %} {% block _layout %} {% if title is defined %}{{ title }} - {% endif %}{{ siteName }} {% for templatehead in craft.entries.section('siteGeneral').limit(1) %} body{ background-color: {{templatehead.backgroundColour}} ; {% set backgroundtemplate = templatehead.backgroundFile.first() %} {% if backgroundtemplate %} background-image: url({{backgroundtemplate.getURL()}}); {% endif %} } body p{ color: {{templatehead.bodyTextColour}}; } #container, #header, #content, #footer, #home{ background-color: {{templatehead.mainBackgroundColour}} ; } h1, h2, h4, h5{ color:{{templatehead.mainTitleColour}}; } h1.subtitle{ border-bottom: 1px solid {{templatehead.borderLineColour}}; } body #container .innerblock p, body #container .innerblock h1, body #container .innerblock h2, body #container .innerblock h3, body #container .innerblock h4, body #container .innerblock h5{ color: {{templatehead.innerBlockTextColour}}; } a, .fakelink{ color: {{templatehead.innerBackgroundColour}}; } .innerblock a{ color: {{templatehead.innerBlockLinkColour}}; } .phone a, .phone:before, .email:before, .hrbottom ul li a:after{ color: {{templatehead.mainTitleColour}}; } ul li ul.subnavmenu .subnavitemwrap{ border-color: {{templatehead.mainTitleColour}}; } ul li ul.subnavmenu li.subnavitem a::after{ background-color: {{templatehead.mainTitleColour}}; } .phone, .email{ color: {{templatehead.bodyTextColour}}; } .innerblock, .mobilemenuwrap{ background-color: {{templatehead.innerBackgroundColour}}; {% set boxbackground = templatehead.innerBackgroundImage.first() %} {% if boxbackground %} background-image: url({{boxbackground.getURL()}}); {% endif %} background: {{templatehead.innerBackgroundColour}} url({{boxbackground.getURL()}}) no-repeat center top; color: {{templatehead.innerBlockTextColour}}; } .innerblock p, .innerblock h1, .innerblock h2, .innerblock h3, .innerblock h4, .innerblock h5{ color: {{templatehead.innerBlockTextColour}}; } .slidewrap{ border-top: 1px solid {{templatehead.borderLineColour}}; } #footer{ background-color: {{templatehead.innerBackgroundColour}}; } .leftfooter a{ color: {{templatehead.innerBackgroundColour}}; } {% endfor %} Title: {{title}}
Title3: {{title3}} Menu
- Home
{% for tempNav in
craft.entries.section(‘contentPages’).order(‘displayOrder’) %} {%
if tempNav.isMainPage == “yes” %} {% set parents =
tempNav.childPages %} {{tempNav.title}} {% if parents | length %}
{% for subNav in parents %} {{subNav.title}}{% endfor %}
{% endif %} {% endif %} {% endfor %}
{% for tempEntry in craft.entries.section('siteGeneral').limit(1) %} Menu {% set logoimage = tempEntry.siteLogo.first() %} {% if logoimage %} {% endif %} Search Email us Call us: {{tempEntry.phoneNumber}}
Email us: {{tempEntry.siteEMail}} Call us: {{tempEntry.phoneNumber}}
- {% for tempNav in
craft.entries.section(‘contentPages’).order(‘displayOrder’) %} {%
if tempNav.isMainPage == “yes” %} {% set parents =
tempNav.childPages %} {{tempNav.title}} {% if parents | length %}
{% for subNav in parents %} {{subNav.title}}{% endfor %}
{% endif %} {% endif %} {% endfor %}
{% endfor %} {% block content %} {% endblock %} CONNECT WITH US --> {% for tempNav in craft.entries.section('contentPages').order('displayOrder') %} {% if tempNav.footerLink == "yes" %}
{% endif %} {% endfor %} {% for tempEntry in craft.entries.section('siteGeneral').limit(1) %}
{{tempEntry.footerAddressLine}}
{{tempEntry.footerLegalLine}} {% endfor %} title: {{title}} {% endblock %}
コンテンツ:
{# # Content Page Template # --------------- # #} {% extends "_layout" %} {% block content %} {% set entries = craft.entries({ slug: craft.request.getSegment(2) }).section(content) %} {% for content in entries %} {% set title = content.title %} Title: {{title}} {% for slide in content.mainImage %} {% endfor %} {{ content.textMainImageOverlay }} {{content.innerPageTitle}} {% if content.innerPageTitleAdditional is not empty %} - {{content.innerPageTitleAdditional}} {% endif %} {{content.innerboxText}} {% for image in content.innerboxImage %} {% endfor %} {% for block in content.mainContentArea %} {% for image in block.sectionImage %} {% endfor %} {{block.sectionTitle}} {{block.sectionText}} {% endfor %} {% set myClasses = ['left', 'center', 'right'] %} {% for block in content.pictureSection.type('heading') %} {% if block.type == "heading" %} {{block.header}} {{block.textSection}} {% endif %} {% endfor %} {% for block in content.pictureSection.type('images') %} {% if block.type == "images" %} {% for image in block.image %} {% endfor %} {{block.label}} {% endif %} {% endfor %} {% endfor %} {% endblock %}
これはトリックを行う必要があります
{% extends "_layout" %}
{# do you use a custom routing or why do you repull the entry #}
{# you know craft presents you the entry if you are in a entrypage #}
{# so just using title = entry.title will be enough because the global entry variable already exists #}
{% set entry = craft.entries({ slug: craft.request.getSegment(2) }).section(content).first() %}
{% set title = entry.title %}
{% block content %}
Title: {{ title }}
<div class="slidewrap">
<div id="slider">
<div class="slides slide" style="">
<div class="slideimgwrap">
{% for slide in entry.mainImage %}
{% endfor %}
</div>
<div class="slideoverlay">
<div class="plainblock">
<div class="slideoverlayinner">
{{ entry.textMainImageOverlay
}}
}}
</div> </div> </div> </div> </div> </div>
{{ entry.innerPageTitle }} {% if
entry.innerPageTitleAdditional is not empty %} -
{{ entry.innerPageTitleAdditional
}} {% endif %}
entry.innerPageTitleAdditional is not empty %} -
{{ entry.innerPageTitleAdditional
}} {% endif %}
<div class="innerblock"> <div class="plainblock"> <div class="mainboxlefttext"> {{ entry.innerboxText }} </div> <div class="mainboxrightimage hidemobile"> {% for image in entry.innerboxImage %}{% endfor %} </div> </div> </div> <div class="plainblock"> {% for block in entry.mainContentArea %} <div class="imageblock {% if block.sectionImageLocation == "left" %} left{% endif %}{% if block.sectionImageLocation == "right" %}right{% endif %}{% if block.sectionImageLocation == "noImage" %}noimage {% endif %}"> <div class="image"> {% for image in block.sectionImage %}
{% endfor %} </div> <div class="text">
{{ block.sectionTitle }}
{{ block.sectionText }} </div> </div> {% endfor %} {% set myClasses = ['left', 'center', 'right'] %} {% for block in entry.pictureSection.type('heading') %} {% if block.type == "heading" %} <div class="imageblock noImage noBottom"> <div class="text">
{{ block.header }}
{{ block.textSection }} </div> </div> {% endif %} {% endfor %} {% for block in entry.pictureSection.type('images') %} {% if block.type == "images" %} <div class="{{ cycle(myClasses, loop.index0) }} imagebox"> {% for image in block.image %}{% endfor %} {{ block.label }} </div> {% endif %} {% endfor %} </div> <div class="plainblock footimage">

</div> {% endblock %}