There are two files that I am able to modify
header.tpl and product.tpl
I do not have access to any of the controller or model files
For SEO purposes I am trying to modifiy the following meta data while on a product page.
<meta name="description" content="<?php echo $description; ?>" />
Currently $description
does not have any output. However on my product.tpl
I have a variable <?php echo $heading_title ?>
which is essentially the text that I would like to have in the header meta
data.
Is this even possible to achieve without accessing the model/controller or am I just wasting my time?
2
Answers
The not so pretty but functional solution
As noted in the comments: Once something has been sent to the browser (or any other output), it is impossible to change it server-side.
The best solution, if you are able to edit the contents of the header with
preg_replace()
etc, is to simply set the variable before including the header.So that instead of something like this:
You move all of the processing before you start to output anything to the browser, which completely eliminates the paradox of having to change something you’ve already sent. Which should leave you with a code looking something like this:
It also has the added benefit of making your PHP code much simpler to read, and thus easier to maintain in the long run. Even on this small code sample, you can see the difference a proper seperation of concerns does.