Variable scoping across <?php ...?> blocks with HTML interspersed -
i new webscripting , technologies. please pardon me if basic query. further have been researching day , haven't been able figure out why not working.
i trying improve website wife. design dictates have common header.php file can included various static pages website contains.
now new requirement, want target few static pages targeting different keywords, , company wants setup different "heading message". want dynamically pass different "$page_heading" before include header.php.
my header.php has bunch of html code interspersed in between , following doesn't seem working:
in <mypage.php>: ... <body> <div class="container"> <?php //global page_header; $page_header = 'a wildlife resort of south india'; include('header.php'); ?> ... in <header.php>: <header class="row-fluid"> <div class="header-main"> <a href="http://www.innthewild.com" class="pull-left"><img src="http://www.innthewild.com/img/itw-logo.png" alt="inn wild" style="margin-top:8px;"/></a> <div class="pull-right" style="height: 20px;"> <nav> ... <div class="heading pull-right"> <?php if(!isset($page_heading)) { $page_heading = 'a wilderness retreat — masinagudi jungle resort, india'; } echo $page_heading; ?> </div> ...
the above seems should work straight up, variable seems losing scope across new instance. how make work?
here example pages: http://www.innthewild.com , http://innthewild.com/resorts-places-around-bangalore.php
you're calling $page_header
in mypage.php
, $page_heading
in header.php
.
change 1 or the other variable name matches across them
Comments
Post a Comment