Jump to content

render children


Roberts R
 Share

Recommended Posts

As im statring to use

$config->useMarkupRegions = true;

I'm starting to run in things I can't figure out.

In body field I have hanna code inserted that renders some of children and children have template.  When rendering children they include

$config->prependTemplateFile = '_init.php';
$config->appendTemplateFile = '_main.php';

for all rendered children.

Is there a way to render without them?

Link to comment
Share on other sites

Sorry, I don't get your question. What is your exact setup, what is the problem? What is your hanna code? Why do the children prepend + append the template file and why is that not placed in the config.php file?

Link to comment
Share on other sites

Ok let me try again.

My config file :

$config->useMarkupRegions = true;
$config->prependTemplateFile = '_init.php';
$config->appendTemplateFile = '_main.php';

Child template in ./templates/child.php

<div class="child">
    <div class="image" style="background-image:url('<?=$page->backgroundImage->url?>')"></div>
    <div class="description">
        <h3><?=$page->title?></h3>
        <p><?=$page->smallDescription?></p>
        <div class="price">CHF <?=$page->price?>.-</div>
    </div>
</div>

Hanna code :

<?php foreach ($page->children('template=child') as $child) {
 echo $child->render();
} ?>

parent template is just :

<main pw-replace="main">
	<?=$page->body?>
</main>

 

And question is how do render child without "_init.php" and "_main.php"?

 

 

Link to comment
Share on other sites

You can send an $options array with the render method and use that in child.php

So in your Hanna code

echo $child->render(array("useMain" => false));

Then in child.php before your other markup

<? if(isset($options['useMain'])) $useMain = $options['useMain']; // this will give you false when rendered from Hanna code ?>

and somewhere in the top area of your  your _main.php

<? if(isset($useMain) && !$useMain) return; ?>

This will take care of not rendering _main.php

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

7 minutes ago, gebeer said:

You can send an $options array with the render method and use that in child.php

So in your Hanna code


echo $child->render(array("useMain" => false));

Then in child.php before your other markup


<? if(isset($options['useMain'])) $useMain = $options['useMain']; // this will give you false when rendered from Hanna code ?>

and somewhere in the top area of your  your _main.php


<? if(isset($useMain) && !$useMain) return; ?>

This will take care of not rendering _main.php

Ah this is what I can use when running Ajax (last part). Thank you as well.

  • Like 1
Link to comment
Share on other sites

ProcessWire is a lot more than just the API. Lots of hidden treasures inside the /wire folder - just have a look and see the comments in all those files.

1 minute ago, Roberts R said:

Ah this is what I can use when running Ajax (last part). Thank you as well.

if($config->ajax == true) {
	// do ajax stuff
}

 

  • Like 1
Link to comment
Share on other sites

There are also specific elements within the $page->render() $options array for prependFile and appendFile, see here.

So you can do:

foreach($page->children('template=child') as $child) {
    echo $child->render(['prependFile' => null, 'appendFile' => null]);
}

 

  • Like 2
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

×
×
  • Create New...