Jump to content

wireRenderFile() pass value to $page->title


charger
 Share

Recommended Posts

I'm using wireRenderFile() to include the following teaser-event.php file:

<div class="event-teaser">
    <?=$page->title?>
</div>

Now, is it possible to pass a value to $page->title? Because the folling isn't working, as this would expect a $title variable in teaser-event.php.

<?=wireRenderFile("components/teaser-event", array('title' => 'New event title'))?>

I imagined something like this:

<?=wireRenderFile("components/teaser-event", array('page.title' => 'New event title'))?>

Am I doing something wrong, or is this simply not possible at the moment?

Link to comment
Share on other sites

$page refers to the actual page being viewed, title is the field "title" belonging to this page. I guess you don't want to set a new title on the page. It works like this:

<?=wireRenderFile("components/teaser-event", array('title' => 'New event title', 'another_var' => 'Blub'))?>

// In the template file teaser-event.php
<?= $title ?>
<?= $another_var ?>
Link to comment
Share on other sites

I don't want to change the $page->title variable of the page I'm on, but the one that's included in the teaser-event.php. I usually set up my includes/components/partials/whatever to simply use the $page->title variable instead of making a $title variable. Because often, that's exactly what I want the includes to do. And if not, I just override the $page e.g. like this:

<?=wireRenderFile("components/sub-nav", array('page' => $pages(1234)))?>

I hope that was understandable :)

Link to comment
Share on other sites

$pages(1234) is valid according to Ryan.

Again, I don't want to pass a value to the $page variable in my include file, but to the $page->title variable. The above was just an example to explain how I usually work with includes.

Link to comment
Share on other sites

If you're view file is echoing "$page->title" there needs to be a $page variable, no matter how you turn it. "$page->title" is not a own entity (e.g variable), but a part of the $page object. If you want to have a different title the object needs to change. The only way to archive this with wireIncludeFile is by passing a $page object with the title changed. You cannot change the $page object which is automatically added by the TemplateFile class.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...