Jump to content

Recommended Posts

Posted

Hello everyone.

I've found PW recently and I've been exploring/testing it...

The everything is a Page is slowly sinking in.

I'm currently trying to render a page in another (like a partial) like below:

$shop = $pages->get('/shops/mr-big');
$mainContent = $shop->render('partials/shop-intro.php');

I also have set an $config->appendTemplateFile.

How can I prevent the appendFile to be included for this partial rendering.

I've search the forums and docs but could not find an answer...

Thank you

Posted

This should do the job.

$shop = $pages->get('/shops/mr-big');

$temp = $config->appendTemplateFile;
$config->appendTemplateFile = '';

$mainContent = $shop->render('partials/shop-intro.php');

$config->appendTemplateFile = $temp;
Posted

Hello LostKobrakai,

That worked!

Thinking some method of doing this should exist.

Is this Module playfield or am I doing it wrong and there are more appropriate ways?

My goal is to render a "snippet" of an existing page.

Think latest news intro or blog list post intro..

Thanks for your reply.

Posted

There's no method cause a page->render() usually needs the init. Depends what you have in your init, but there shouldn't be anything big going on there.

Posted

There's many different options, so there's also a option to overwrite it in the render options.

$p->render("template", array("prependFile" => ""));
  • Like 2
Posted

I you're searching for a more flexible way to include snippets / not always whole sites, maybe this is a more appropriate function:

// returns the output of snippets/contactform.php
// the second argument is optional and will be passed to 
// the called file as multiple variables with the name of the key
// also all api varables are available by default

wireRenderFile("snippets/contactform", array("stuff" => $something ));
  • Like 4
Posted

Ah! That looks much better... complete code below

/**
 * site/config.php
 */
$config->appendTemplateFile = '_layout.php';
/**
 * site/templates/home.php
 */
$title = $page->title;
$shop = $pages->get('/shops/mr-big');
$mainContent = $shop->render('partials/shop-intro.php', ['appendFile'=>null]);
/**
 * site/templates/partials/shop-intro.php
 */
<div class="shop-intro">
<h2><?= $page->title ?></h2>
<?php foreach( $page->shop_photos AS $photo ) : ?>
  <img src="<?= $photo->url ?>" /><br/>
<?php endforeach; ?>
<div class="shop-desc">
  <?= html_entity_decode($page->shop_description) ?>
</div>
</div>
/**
 * site/templates/_layout.php
 */
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><?= $title; ?></title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<h1><?= $title; ?></h1>
<div class="container">
<?= $mainContent ?>
</div>
</body>
</html>
 

I like it like this...

If anyone has a better way, feel free to jump in.

  • Like 2
Posted

Didn't know about wireRenderFile(...)

Thank you LostKobrakai.

For the situation at hand, Soma's tip seems more natural.

But the wireRenderFile may be very useful in other ways...

Thank you both.

  • Like 1
Posted

thanks for wireRenderFile

until now i was doing this like it is done in the blog profile: https://github.com/ryancramerdesign/BlogProfile/blob/cca31ebb7ec10f7614044156161abe3042abbbed/templates/categories.php#L20

drawback was, that the api variables where not directly accessible in the template file ( wire('page') instead of $page ). is there any reason why the blog profile uses a different approach?

Posted

wireRenderFile() / wireIncludeFile() are new shortcuts to the old TemplateFile markup used in the blog profile. They were introduced somewhere around 2.5.0, so they're to new for the blog profile.

  • 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
×
×
  • Create New...