Jump to content

How to modify already echoed variable?


Anti-Moronic

Recommended Posts

Ok, here's what I'm trying to do. In Zend, you can modify a template title for a page within the actual template file even though the title has already been set.

 

So, say I have this in a common header file:

 


<?php echo $title; ?>

 

..but I then want to maybe change that within my main template page, say my 'about' page. How would I go about that?

 

Currently I do this:

 

include($commonheader);

include($content);

include($footer);

 

It's in the content where I want to be able to change the title in the header, should I need to. You can do this with Zend but it's beyond me how they do it.

 

Should note, the above is for simplicity sake. I am doing this using OOP methods.

 

Any help appreciated. Maybe ob_flush?

Link to comment
Share on other sites

Well I'm certainly not referring to the company :-)

 

Yes, I'm using MVC. But I'm new to OOP and I'm having trouble on this point.

 

If I include the different template partials, then they are outputted immediately and I cannot modify any output variables in one of the partials which come after.

 

Like now, I can't modify the title in my content partial which is outputted in my header partial because it's been 'included' and so already output.

 

How should I go about this?

 

Thanks for the reply.

Link to comment
Share on other sites

In most of my setups, I have this in my layout.phtml:

<title><?php echo $this->title; ?></title>

 

And then, this in each of my view scripts:

<?php $this->title = 'Test Page Name'; ?>

 

Alternatively, I could set $this->view->title in my controllers and it'd still get outputted in my layout.phtml script. I'm almost sure partial view scripts would act the same, but I've never tried it.

Link to comment
Share on other sites

I see, thanks!

 

Now do you have any idea how I do this without Zend Framework?

 

To clarify my problem:

 

 

I have 2 files like this:

 

header>>

<?php echo $title; ?>

 

 

content>>

<?php $title = 'something else'; ?>

 

..and then the template:

 

include(header)

include(content)

 

====

 

That is very simplified and not at all like what I actually have. But it demonstrates my confusion. How do I put together a template whereby I can edit variables in the header, from within the content before output?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.