

PHP passing values to variables in included files
source link: https://www.codesd.com/item/php-passing-values-to-variables-in-included-files.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

PHP passing values to variables in included files
I have a php file (article.php) with variables holding content and an include reference to a template holding the html structure (template.php).
<?php
$headline = 'Headline';
$author = 'Author';
$paragraph = 'Text';
include 'template.php';
?>
This is template.php noted above. It includes blockTemplate.php. (More on that, below.):
<html>
<body>
<?php include 'blockTemplate.php'; ?>
</body>
</html>
This is blockTemplate.php. It has variables, the values to which I want to provide in article1.php, (the top level file):
<h1>Title: <?php $headline ?></h1>
<h2>Author: <?php $author ?></h2>
<p>Text: <?php $paragraph ?></p>
Here's the output I should be getting from article1.php:
Title: Headline
Author: Author
Text: text
Here's the output I am getting. Note the variables didn't get included:
Title:
Author
Text:
Question: how can I pass values in article1.php to the variables in included blockTemplate.php? Is what's happening the included files are being processed before inclusion so that contain no variables by the time they are included?
Have you tried:
<h1>Title: <?php echo $headline ?></h1>
<h2>Author: <?php echo $author ?></h2>
<p>Text: <?php echo $paragraph ?></p>
That works for me
Recommend
-
9
Extracting values from environment variables in tox Tox is a great tool for automated testi...
-
13
Standard Django: Passing Form Values in URL Lets say you have a form that is used to drive the next page. For example, it might contain parameters for running a report. One way to ha...
-
18
README This is a mirror of
-
10
Passing variables via functions in C ++ advertisements So I'm trying to write a basic program in C++ to get the cost of something, the quantit...
-
4
Passing values eats my URLs advertisements Just upgraded from 1.3 to 2.0.3 and I'm trying to migrate all the changes. I'm...
-
8
Predefine values of custom pipeline variables February 08, 2022 < 1 min read Share Recently, we
-
9
Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us wh...
-
25
Rajesh Shivajirao Shinde Jul 26, 2021 at 08:03 PM SAP PO 7.5 REST Lookup - Issues in passing dynamic values in HTTP Header and custom E...
-
8
Details (Whiteboard: [fidefe-reusable-components-ms1])...
-
8
Sivakami P Subramanian June 9, 2023 1 min...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK