Jump to content

Passing variables using wireRenderFile


cb2004
 Share

Recommended Posts

I am having some trouble passing variables using a new template technique I am trying.

_main.php contains my main template with the line <?php echo $content; ?>

I then have a template, lets say basic-page.php which contains:

<?php
 
$content = wireRenderFile("views/page");
include("./_main.php");

Within views/page.php I have a variable $JS. Why is that not appearing in my _main.php file? If I put the variable in basic-page.php it appears ok.

Link to comment
Share on other sites

wireRenderFile does not inherit variables by default, that's not possible in php. But you can pass variables manually.

// basic-page.php
$js = "something";
$content = wireRenderFile("views/page", array("jsToFile" => $js));
include("./_main.php");

// views/page
echo $jsToFile;
  • Like 1
Link to comment
Share on other sites

Cheers for your reply

Yes I have just discovered its not possible with PHP, I kind of knew it was but was curious.

My current setup is:

basic-page

+includes views/page

+includes main

How would I pass something from views/page to main?

Link to comment
Share on other sites

  • 1 year later...

I'm having a few issues with wireRenderFile in PW3.

In my _init.php i have:
 

// process site notes
$data = array('notices',$notices);	// $notices is processwire array
$partials = wireRenderFile('views/partials/_notices',$data);

Doesnt seem to work, I assume this has something todo with the File Compiler?

Link to comment
Share on other sites

22 minutes ago, Mackski said:

$data = array('notices',$notices);

That looks a bit strange to me. You are saying data is an array where the first value is the string 'notices' and the second value is the WireArray $notices - is that intentional?

Or do you maybe mean:

$data = array('notices' => $notices);

 

  • Like 3
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...