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

How do I pass variables between templates???

Development and Programming

charlie spider's avatar
charlie spider
125 posts
14 years ago
charlie spider's avatar charlie spider

So I have different blocks of HTML broken up into different templates that get embedded into one master layout template.

for example, a typical inner page template :

{embed="block/.html_header"}
{embed="block/.header"}

<div id="content">
 {exp:channel:entries channel="pageContent"}
  -- content here --
 {/exp:channel:entries }

 {embed="blocks/.sidebar" sbr_flt="right"}
</div>

{embed="blocks/.footer"}

In the html_header template, I have some PHP that sets some variables depending on which page of the site you are on.

How do I pass the variables from html_header to other templates like the sidebar template or the footer template ???

Or in other words, how do I dynamically declare variables in one template that can then be available “globally” to all other templates ???

Thanks in advance for any and all help

       
stevenkovar's avatar
stevenkovar
11 posts
14 years ago
stevenkovar's avatar stevenkovar

Hi Brent,

I thought that you could only pass a variable through an embed tag - like you are doing with your “blocks” embed.

Embedded templates are parsed after the parent template, so maybe you could create your “global” variables in your parent template then you can pass it to any embedded templates you want.

Sometimes I’ve found that URL segment conditionals can be useful if your url structure relates to the content that should be shown on the page.

Sorry, it’s not much help… There have been many times when I wanted similar functionality, and had to do a work-around with segment variables or finding a way to pass the variable through an embed.

       
James Smith's avatar
James Smith
259 posts
14 years ago
James Smith's avatar James Smith

Use String, it’s amazing.

http://emarketsouth.com/add-ons/string-plugin

       
stevenkovar's avatar
stevenkovar
11 posts
14 years ago
stevenkovar's avatar stevenkovar

Thanks, that looks cool, I’ll have to check it out.

       

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.