Jump to content

Recommended Posts

Posted

Wondering if I can render out partial content via the API, and pass through either the current page, or a set of variables.

E.g. instead of this:

$content = "<h1>This is the content</h1>";

I'd love to do this:

$content = $something -> render('/site/templates/views/partials/partialcontent.html.php', $page);

I've seen in the API docs the ability to render pages as partials, but I think this is a bit different (e.g. partialcontent isn't a page itself).

  • Like 1
Posted

That's exactly what you want to have. wireRenderFile() and $page->render($options) should be enought t

The example code shown in the blog post,


$photo = $page->photos->getRandom();
$sidebar = wireRenderFile("inc/fancy_sidebar", array('photo' => $photo));

the wireRenderFile() function will auto append .php file extension to fancy_sidebar ?

Posted

I tried testing the wideRenderFile but no success.

a template file

$temp = wireRenderFile("test", array('content' => $page->body)); 
echo $temp;

test.php

<?php 
   
    $content .= "AAAAAAAAAAAAAA";

There is not outputted content of $temp.

Posted

wireRenderFile does return the output of the included file. So everything you echo in test.php will be returned to $temp as string. The passed variables are only made available as copies, but they do not automatically make the function return anything.

  • Like 1

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
  • Recently Browsing   0 members

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