We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

layout:set not passing data when inside channel:entries tag

Development and Programming

WDA's avatar
WDA
8 posts
2 years ago
WDA's avatar WDA

Hi. I’m using a site/_wrapper layout template and, pushing data using layout:set from the parent template (site/index). For example:

{layout="site/_wrapper"}
{layout:set name="body_class"}{template_group} {template_name}{/layout:set}

{exp:channel:entries channel="pages" disable="categories|member_data|pagination"}
{layout:set name="meta_title"}{title}{/layout:set}
<h1>{title}</h1>
{/exp:channel:entries}

I am getting an issue where the body_class variable passes through fine but the meta_title one inside the entries tag does not. The title does display so the entries tag is returning data. The debug actually lists the meta_title one under undefined variables in this scenario. I’ve also tried test data with the meta_title one outside the entries tag to check the variable was correct and that does pass data through.

If I reverse it round so the entries tag is inside the layout:set like this…

{layout:set name="meta_title"}{exp:channel:entries channel="pages" disable="categories|member_data|pagination"}{title}{/exp:channel:entries}{/layout:set}

…then that does pass the variable data. So it looks like the layout:set tags are not being processed inside the entries tag.

This is using EE 7.3.14 on PHP8.2. I came across this issue running it on MAMP on my local system but have since set it up on a live server and I’m still getting the same issue.

Is there a bug in this version or have I missed something?

Thanks for any help.

       
Russ K.'s avatar
Russ K.
174 posts
2 years ago
Russ K.'s avatar Russ K.

Hi there. Did you try changing the layout variable name? Like maybe “meta_title_custom” or something like that? I usually find when I have one variable that works and another that doesn’t it is because of clashing variable names.

Hope thats of some help.

One other thing… You CAN set layout tags within a Channel Entries tag pair, but I think only if you are expecting only a Single entry to be returned. If there are more than a single entry you may need to look at {layout:set:append} tags.

       
WDA's avatar
WDA
8 posts
2 years ago
WDA's avatar WDA

Thanks Russ. I’ve tried renaming but still no joy. That entries tag should only have a single entry (I’ve got limit=”1” and require_entry set on it now on the actual template). I’ve often used this approach to push meta data and other information based on the entry’s content to a wrapper template so I can customise the display so it’s a bit strange why it’s not working this time.

Just to confirm, this is the full code in the index template so far:

{layout="site/_wrapper"}
{!-- <!-- Template: site/index || Home --> --}

{layout:set name="breadcrumb"}<a href="http://{path=contact}">Contact us</a>{/layout:set}
{layout:set name="body_class"}{template_group} {template_name}{/layout:set}

{exp:channel:entries channel="pages" entry_id="2" disable="categories|member_data|pagination" dynamic="no" limit="1"}
 {layout:set name="meta_title_custom"}{title}{/layout:set}
 {layout:set name="meta_description"}{meta_description}{/layout:set}
 {layout:set name="meta_custom"}{meta_custom}{/layout:set}
 <!-- other field content to be added -->
{/exp:channel:entries}

…and then the _wrapper template:

{!-- <!-- Template: site/_wrapper --> --}
<!doctype html>
<html>
 
 <head>
  <meta charset="{charset}">
  <title>{layout:meta_title_custom} | {site_name}</title>
  <link rel="stylesheet" href="{stylesheet=site-css/nium-core.css}">
 </head>
 
 <body class="{layout:body_class} {layout:title_section_class}">
  <a href="#main" class="skiplink">Jump to content</a>
  <div class="site-outer">
   <div class="site-content">
    
    <header id="header" class="site-header">
     <div class="site-header-inner">
      <div class="site-title"><a href="http://{homepage}">{site_name}</a></div>
       <nav id="nav" class="site-nav">
        <input id="display_nav" type="checkbox" value="y">
        <label for="display_nav"><span>Show navigation menu</span></label>
        <div id="nav_menu" class="menu"><!-- menu to go here --></div>
       </nav>
      {/exp:channel:entries}
      {if layout:breadcrumb}<div class="breadcrumb">{layout:breadcrumb}</div>{/if}
     </div>
    </header>
    
    <main id="main" class="site-main">{layout:contents}</main>
    
    <footer id="footer" class="site-footer"></footer>
    
   </div>
  </div>
 </body>
 
</html>

I’ve include a screenshot of the variables info from the debug where you can see the meta_title_custom is undefined (title_section_class is one that will be added for layout options but I’m having the same issue with that when trying to use it in an entries tag).

       
WDA's avatar
WDA
8 posts
2 years ago
WDA's avatar WDA

I’ve just tried it disabling custom_fields in the entries tag and the title is pushed through fine to that variable so maybe the issue is elsewhere rather than with the variables. I’ll try a few more options and see if I can track it down!

       
WDA's avatar
WDA
8 posts
2 years ago
WDA's avatar WDA

Thanks. I’ve tried a few other things since, but it looks like increasing the server setting for max_input_vars appears to have solved it (was 1000, set to 2000).

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.