Jump to content

Problem wireRenderFile()


Orkun
 Share

Recommended Posts

Hi Guys

I have 3 files. 

  • templates/signup-form-formbuilder.php
  • partials/sharedtemplates/signup-form-formbuilder.php
  • _main.php

I outsourced the code from templates/signup-form-formbuilder.php to partials/sharedtemplates/signup-form-formbuilder.php. 

In the templates/signup-form-formbuilder.php file I am doing this: 

$out .= wireRenderFile('partials/sharedtemplates/signup-form-formbuilder.php');

 

It works. The content of the file in the sharedtemplates will be rendered inside the original template file and the outputed in the _main.php with $out variable. But the problem now is, that I have this code inside of the _main.php in the head section to render the formbuilder styles: 

if(isset($formFormBuilder)){
	echo $formFormBuilder->styles;
	echo $formFormBuilder->scripts;
}

The $formFormBuilder was defined before in the original template file (templates/signup-form-formbuilder.php) . But now it is defined in the file inside shardetemplates folder (partials/sharedtemplates/signup-form-formbuilder.php). Since wireRenderFile just outputs the content it can't recognize the $formFormbuilder inside of the (partials/sharedtemplates/signup-form-formbuilder.php) file since the whole file content is outputted already in the $out var. It worked before, because the _main.php file is always append to the templates.

I had to outsource the code of the original template, because I need to output the form also on other templates.

How can I make the $formFormBuilder available again for the _main.php?

Link to comment
Share on other sites

Hi, One way to solve such issues is to prepare separate collentions to be outputted into both the <head> and the footer, like this:

https://github.com/NinjasCL/pw-ghost/blob/c192001567b73063dac3cdae72e6e19bbf08e632/templates/_main.php#L35-L38

so when you need something extra on a given page, you just add it to the collection:

https://github.com/NinjasCL/pw-ghost/blob/c192001567b73063dac3cdae72e6e19bbf08e632/templates/blog-item.php#L59

more on this:

https://github.com/NinjasCL/wire-render-pattern

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