<p>This should do the trick</p>

<pre><code>{% 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 }}
        &lt;div class="slidewrap"&gt;
            &lt;div id="slider"&gt;
                &lt;div class="slides slide" style=""&gt;
                    &lt;div class="slideimgwrap"&gt;
                        {% for slide in entry.mainImage %}
                            &lt;img src="{{ slide.url }}" alt="{{ entry.title }}" class="mySlides"&gt;
                        {% endfor %}
                    &lt;/div&gt;
                    &lt;div class="slideoverlay"&gt;
                        &lt;div class="plainblock"&gt;
                            &lt;div class="slideoverlayinner"&gt;
                                &lt;h2 class="slidetext"&gt;{{ entry.textMainImageOverlay }}&lt;/h2&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;h1 class="pagetitle"&gt;{{ entry.innerPageTitle }}
            {% if entry.innerPageTitleAdditional is not empty %}
                &lt;span class="hidemobile"&gt; - &lt;/span&gt;&lt;br class="mobileonly"&gt;
                &lt;span class="smallmobile"&gt;{{ entry.innerPageTitleAdditional }}&lt;/span&gt;
            {% endif %}
        &lt;/h1&gt;


        &lt;div class="innerblock"&gt;
            &lt;div class="plainblock"&gt;
                &lt;div class="mainboxlefttext"&gt;
                    {{ entry.innerboxText }}
                &lt;/div&gt;
                &lt;div class="mainboxrightimage hidemobile"&gt;
                    {% for image in entry.innerboxImage %}
                        &lt;img src="{{ image.url }}"/&gt;
                    {% endfor %}

                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;div class="plainblock"&gt;
            {% for block in entry.mainContentArea %}
                &lt;div class="imageblock {% if block.sectionImageLocation == "left" %} left{% endif %}{% if block.sectionImageLocation == "right" %}right{% endif %}{% if block.sectionImageLocation == "noImage" %}noimage {% endif %}"&gt;
                    &lt;div class="image"&gt;
                        {% for image in block.sectionImage %}
                            &lt;img src="{{ image.url }}"/&gt;

                        {% endfor %}
                    &lt;/div&gt;
                    &lt;div class="text"&gt;
                        &lt;h2 class="title"&gt;{{ block.sectionTitle }}&lt;/h2&gt;
                        {{ block.sectionText }}

                    &lt;/div&gt;
                &lt;/div&gt;
            {% endfor %}
            {% set myClasses = ['left', 'center', 'right'] %}
            {% for block in entry.pictureSection.type('heading') %}
                {% if block.type == "heading" %}
                    &lt;div class="imageblock noImage noBottom"&gt;
                        &lt;div class="text"&gt;
                            &lt;h2 class="title"&gt;{{ block.header }}&lt;/h2&gt;
                            {{ block.textSection }}
                        &lt;/div&gt;
                    &lt;/div&gt;
                {% endif %}
            {% endfor %}
            {% for block in entry.pictureSection.type('images') %}
                {% if block.type == "images" %}
                    &lt;div class="{{ cycle(myClasses, loop.index0) }} imagebox"&gt;
                        {% for image in block.image %}
                            &lt;img src="{{ image.url }}"/&gt;
                        {% endfor %}
                        {{ block.label }}
                    &lt;/div&gt;
                {% endif %}

            {% endfor %}

        &lt;/div&gt;
        &lt;div class="plainblock footimage"&gt;
            &lt;h1 class="pagetitle subtitle" style="height: 27px;"&gt;&lt;img src="/images/divide_logo.jpg"
                                                                      style="width: auto; background-color: #fff; height: auto; padding: 0 10px;"&gt;
            &lt;/h1&gt;
        &lt;/div&gt;
{% endblock %}
</code></pre>

CC BY-SA 3.0
2017-10-26T09:15:36.983Z
{# do you use a custom routing or why do you repull the entry #}

First craftcms project and I'm paranoid about it doing what I want it to ;)
I see now, by adding the
    {% set title = entry.title %}
before the 
    {% block content %} 
tag, it allows it to be seen by the layout template as well.

That was pretty much the only bit I was missing.

Much appreciated!
Drenzul
CC BY-SA 3.0
2017-10-26T09:24:54.920Z
Yes and please don't use that `{% set entry = craft.entries.... %}` you always have the `entry` variable if you are in an entry and the `category` variable if you are in a category. No need to fetch them. As well as these https://craftcms.com/docs/templating/global-variables
Robin Schambach
CC BY-SA 3.0
2017-10-26T11:59:55.790Z
gotcha, too used to using Expression Engine :)
Drenzul
CC BY-SA 3.0
2017-10-26T08:44:21.740Z
2017-10-26T08:44:21.740Z
Robin Schambach
<p>So, I'm using the standard template system that comes with craft, which has this code in it:</p>

<pre><code>        &lt;main {% if craft.request.getSegment(1) != "" %}id="content"{% endif %}{% if craft.request.getSegment(1) == "" %}id="home"{% endif %} role="main"&gt;
            {% block content %}
                &lt;p&gt;If you see me, you haven’t set your &lt;code&gt;{% verbatim %}{% block content %}…{% endblock %}{% endverbatim %}&lt;/code&gt; yet.&lt;/p&gt;
                &lt;p&gt;See Twig’s &lt;a href="http://twig.sensiolabs.org/doc/templates.html#template-inheritance"&gt;Template Inheritance&lt;/a&gt; documentation for an explanation.&lt;/p&gt;
            {% endblock %}
        &lt;/main&gt;
</code></pre>

<p>Clearly I've added a bit extra in there to set an ID on it. </p>

<p>Now as the page content is defined inside Block content, so it only knows what title to use inside block content, how to I get the Title out from the inner template back to the layout template to display here:</p>

<pre><code>&lt;title&gt;{% if title is defined %}{{ title }} - {% endif %}{{ siteName }}&lt;/title&gt;
</code></pre>

<p>Currently it just always displays the sitename which is no good. It should be getting the title from the title of whichever page is been pulled in as content which the content section works out from the CraftCMS routes/section information.</p>

<p>Since this is the default layout provided in Craft, there must be a simple way to do this!</p>

<p>I've tried making sure the title variable is defined inside the content template but I can see that any variable I set inside the content template is never accessible in the _layout template.</p>

<p>Heres the extra bits of relevant code:</p>

<p>Layout: </p>

<pre><code>&lt;title&gt;{% if title is defined %}{{ title }} - {% endif %}{{ siteName }}&lt;/title&gt;
</code></pre>

<p>Content:</p>

<pre><code>{% for content in entries %}
{% set title = content.title %}
</code></pre>

<p>Thanks in advance!</p>

<p>Layout:</p>

<pre>
    {#
 # 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}}<br />
    Title3: {{title3}}
    
        
            Menu</p>
            <ul>
                <li>Home</li>
                {% 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}}</li>
                                            {% endfor %}

                                </ul>
                            {% endif %}
                        </li>
                    {% endif %}
                {% endfor %}
                <li><a href="/contactus">CONTACT</a></li>
            
        
        
            {% for tempEntry in craft.entries.section('siteGeneral').limit(1) %}
            
                

                                        

                                            
                                            
                        


                
                
                    

                        Menu</p>



                    
                    {% set logoimage = tempEntry.siteLogo.first() %}
                    {% if logoimage %}
                        
                        
                            
                        
                        
                    {% endif %}
                    Search</p>
                    
                        Email us
                        Call us: {{tempEntry.phoneNumber}}

                        <br />
                        

                            
                            
                        
                    
                

                
                    
                        Email us: {{tempEntry.siteEMail}}
                        Call us: {{tempEntry.phoneNumber}}
                        

                            
                            
                        

                    
                    
                        <ul>

                        {% 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}}</li>
                                                    {% endfor %}
                                                
                                            
                                        </ul>
                                    {% endif %}
                                </li>
                            {% endif %}
                        {% endfor %}
                            <li><a href="/contactus">CONTACT</a></li>
                        
                    
                

            {% endfor %}
            

        

        
            {% block content %}
{% endblock %}
        


        
            
                
                
                CONNECT WITH US

                 -->
            
            
                
                {% for tempNav in craft.entries.section('contentPages').order('displayOrder') %}
                    {% if tempNav.footerLink == "yes" %}
                        <li>{{ tempNav.title }}</li>

                    {% endif %}
                {% endfor %}
                

            
            {% for tempEntry in craft.entries.section('siteGeneral').limit(1) %}
            
                <p>{{tempEntry.footerAddressLine}}</p>
                <p>{{tempEntry.footerLegalLine}}</p>
            
            {% endfor %}
        
        title: {{title}}
    


{% endblock %}
</pre>

<p>Content: </p>

<pre>
{#
 # 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 %}
</pre>

CC BY-SA 3.0
2017-10-24T14:43:37.867Z
what is your `entries` variable? you usually should do `{% set title = entry.title %}`
Robin Schambach
CC BY-SA 3.0
2017-10-24T14:51:09.930Z
Its content, hence the 
{% set title = content.title %} line there.

I can see content.title works as it has data in the inner template, its just its not getting past back out to the outer template. 

It seems to just be dumping everything out in a single pass as even is I manually set a value in the _layout template, it doesn't work unless I use it before I set it in the template. Most systems do multiple passes to get round this even if it does make a certain amount of sense.
Drenzul
CC BY-SA 3.0
2017-10-24T15:09:53.077Z
Do you extend your layout template in the template where you set the page title correct?
Robin Schambach
CC BY-SA 3.0
2017-10-24T15:53:28.033Z
The content template does have this at the top:

    {% extends "_layout" %}
Drenzul
CC BY-SA 3.0
2017-10-24T15:56:38.197Z
And you have the corresponding `blocks` in both entries. You don't overwrite them and when you render something in your content template it is displayed on the page? I never had this issue and just want to make sure you didn't include any mistakes
Robin Schambach
CC BY-SA 3.0
2017-10-25T12:57:05.470Z
Not sure what you mean by that. 

I've got {% block content %} in all my content templates and the {% endblock %} at the end.
Drenzul
CC BY-SA 3.0
2017-10-25T13:07:51.900Z
you need an empty `{% block content %}{% endblock %}` in your layout as well and if you include/extend other templates there must not be a block content or it overwrites your variables/html you set in the content.twig. That allows you to change your menu for some special pages because you are able to overwrite blocks when you include others
Robin Schambach
CC BY-SA 3.0
2017-10-25T14:01:29.303Z
{% block content %}{% endblock %}

Is in the middle of my layout, I've not got anything like that in the head section where the title is however.

It replaces whatever is between those tags with the content section, not sure if I need to do anything extra to make it pass the title tag back to the layout?

I've literally just taken the demo template and added extra bits to the content file and the layout file so its the same as that with all the bits in that.
Drenzul
CC BY-SA 3.0
2017-10-25T14:05:47.477Z
<head>
     <meta charset="utf-8" />
     <meta name="viewport" content="device-width, initial-scale=1.0">
     <title>{% if title is defined %}{{ title }} - {% endif %}{{ siteName }}
    </title>
    (More boring Styles and JS and Stuff!)
    </head>
   <some code to generate the menus from the entries e.t.c.>
   <some code to add logos and mobile styles e.t.c. from singles>
   <main {% if craft.request.getSegment(1) != "" %}id="content"{% endif %}{% if craft.request.getSegment(1) == "" %}id="home"{% endif %} role="main">
   {% block content %}
{% endblock %}
  </main>
<footer>
Drenzul
CC BY-SA 3.0
2017-10-25T14:34:15.093Z
To show what I mean:
http://www.engleburncarehome.co.uk.php704.drenzul.intunet.co.uk/content/about-us

Thats the site in my sandbox.
You can see the title tag set in the content (just below the menu), displays fine. The one at the top of the page (in the layout) doesn't display anything. The code is the same for both {{title}}.
Drenzul
CC BY-SA 3.0
2017-10-25T15:33:44.877Z
I think it would be much easier if you just show us your entire templates.. maybe you overwrite your title somewhere. Because when you loop through your content it's relatively easy to set title to null
Robin Schambach
CC BY-SA 3.0
2017-10-26T08:30:13.647Z
Hi Robin,
  I've added them to the OP now.

I don't think I have overwritten them anywhere as I tried the same with title2 variable as well and produced exactly the same affect.
Drenzul
<templating><entries><meta>
How to set title in layout template from content template
# How to set title in layout template from content template

(Asked by: username_0 on 2017-10-24)

So, I'm using the standard template system that comes with craft, which has this code in it:
        
            {% 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 %}
        

Clearly I've added a bit extra in there to set an ID on it. 
Now as the page content is defined inside Block content, so it only knows what title to use inside block content, how to I get the Title out from the inner template back to the layout template to display here:
{% if title is defined %}{{ title }} - {% endif %}{{ siteName }}

Currently it just always displays the sitename which is no good. It should be getting the title from the title of whichever page is been pulled in as content which the content section works out from the CraftCMS routes/section information.
Since this is the default layout provided in Craft, there must be a simple way to do this!
I've tried making sure the title variable is defined inside the content template but I can see that any variable I set inside the content template is never accessible in the _layout template.
Heres the extra bits of relevant code:
Layout: 
{% if title is defined %}{{ title }} - {% endif %}{{ siteName }}

Content:
{% for content in entries %}
{% set title = content.title %}

Thanks in advance!
Layout:

    {#
 # 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 %}
                CONTACT
            
        
        
            {% 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 %}
                            CONTACT
                        
                    
                

            {% endfor %}
            

        

        
            {% block content %}
{% endblock %}
        


        
            
                
                
                CONNECT WITH US

                 -->
            
            
                
                {% for tempNav in craft.entries.section('contentPages').order('displayOrder') %}
                    {% if tempNav.footerLink == "yes" %}
                        {{ tempNav.title }}

                    {% endif %}
                {% endfor %}
                

            
            {% for tempEntry in craft.entries.section('siteGeneral').limit(1) %}
            
                {{tempEntry.footerAddressLine}}
                {{tempEntry.footerLegalLine}}
            
            {% endfor %}
        
        title: {{title}}
    


{% endblock %}

Content: 

{#
 # 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 %}

**Tags:** templating, entries, meta

> **Comments:**
> **username_1**: what is your `entries` variable? you usually should do `{% set title = entry.title %}`  
> **username_0**: Its content, hence the  {% set title = content.title %} line there.  I can see content.title works as it has data in the inner template, its just its not getting past back out to the outer template.   It seems to just be dumping everything out in a single pass as even is I manually set a value in the _layout template, it doesn't work unless I use it before I set it in the template. Most systems do multiple passes to get round this even if it does make a certain amount of sense.  
> **username_1**: Do you extend your layout template in the template where you set the page title correct?  
> **username_0**: The content template does have this at the top:      {% extends "_layout" %}  
> **username_1**: And you have the corresponding `blocks` in both entries. You don't overwrite them and when you render something in your content template it is displayed on the page? I never had this issue and just want to make sure you didn't include any mistakes  
> **username_0**: Not sure what you mean by that.   I've got {% block content %} in all my content templates and the {% endblock %} at the end.  
> **username_1**: you need an empty `{% block content %}{% endblock %}` in your layout as well and if you include/extend other templates there must not be a block content or it overwrites your variables/html you set in the content.twig. That allows you to change your menu for some special pages because you are able to overwrite blocks when you include others  
> **username_0**: {% block content %}{% endblock %}  Is in the middle of my layout, I've not got anything like that in the head section where the title is however.  It replaces whatever is between those tags with the content section, not sure if I need to do anything extra to make it pass the title tag back to the layout?  I've literally just taken the demo template and added extra bits to the content file and the layout file so its the same as that with all the bits in that.  
> **username_0**: <head>      <meta charset="utf-8" />      <meta name="viewport" content="device-width, initial-scale=1.0">      <title>{% if title is defined %}{{ title }} - {% endif %}{{ siteName }}     </title>     (More boring Styles and JS and Stuff!)     </head>    <some code to generate the menus from the entries e.t.c.>    <some code to add logos and mobile styles e.t.c. from singles>    <main {% if craft.request.getSegment(1) != "" %}id="content"{% endif %}{% if craft.request.getSegment(1) == "" %}id="home"{% endif %} role="main">    {% block content %} {% endblock %}   </main> <footer>  
> **username_0**: To show what I mean: http://www.engleburncarehome.co.uk.php704.drenzul.intunet.co.uk/content/about-us  Thats the site in my sandbox. You can see the title tag set in the content (just below the menu), displays fine. The one at the top of the page (in the layout) doesn't display anything. The code is the same for both {{title}}.  
> **username_1**: I think it would be much easier if you just show us your entire templates.. maybe you overwrite your title somewhere. Because when you loop through your content it's relatively easy to set title to null  
> **username_0**: Hi Robin,   I've added them to the OP now.  I don't think I have overwritten them anywhere as I tried the same with title2 variable as well and produced exactly the same affect.  

---

## 1 answers

### Answer by username_1 on 2017-10-26. Score: 1 | Accepted answer

This should do the trick
{% 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 }}
        
            
                
                    
                        {% for slide in entry.mainImage %}
                            
                        {% endfor %}
                    
                    
                        
                            
                                {{ entry.textMainImageOverlay }}
                            
                        
                    
                
            
        
        {{ entry.innerPageTitle }}
            {% if entry.innerPageTitleAdditional is not empty %}
                 - 
                {{ entry.innerPageTitleAdditional }}
            {% endif %}
        


        
            
                
                    {{ entry.innerboxText }}
                
                
                    {% for image in entry.innerboxImage %}
                        
                    {% endfor %}

                
            
        

        
            {% for block in entry.mainContentArea %}
                
                    
                        {% for image in block.sectionImage %}
                            

                        {% endfor %}
                    
                    
                        {{ block.sectionTitle }}
                        {{ block.sectionText }}

                    
                
            {% endfor %}
            {% set myClasses = ['left', 'center', 'right'] %}
            {% for block in entry.pictureSection.type('heading') %}
                {% if block.type == "heading" %}
                    
                        
                            {{ block.header }}
                            {{ block.textSection }}
                        
                    
                {% endif %}
            {% endfor %}
            {% for block in entry.pictureSection.type('images') %}
                {% if block.type == "images" %}
                    
                        {% for image in block.image %}
                            
                        {% endfor %}
                        {{ block.label }}
                    
                {% endif %}

            {% endfor %}

        
        
            
            
        
{% endblock %}

> **Comments:**
> **username_0**: {# do you use a custom routing or why do you repull the entry #}  First craftcms project and I'm paranoid about it doing what I want it to ;) I see now, by adding the     {% set title = entry.title %} before the      {% block content %}  tag, it allows it to be seen by the layout template as well.  That was pretty much the only bit I was missing.  Much appreciated!  
> **username_1**: Yes and please don't use that `{% set entry = craft.entries.... %}` you always have the `entry` variable if you are in an entry and the `category` variable if you are in a category. No need to fetch them. As well as these https://craftcms.com/docs/templating/global-variables  
> **username_0**: gotcha, too used to using Expression Engine :)  

---

