Jump to content

Template: how to include files OF YOUR CHOICE?


Recommended Posts

Hi, to avoid correcting the same html code in all templates, I wrote it in a separate .php file and then linked from the html page through the following code:

		<?php wireIncludeFile('styles/menu-A.php'); ?>	

But now I would like in the template to be able to choose whether to put the type A menu on the page, or the type B menu.
I used the following code, but it does not work:
 

<?php wireIncludeFile('<?=$page->type_menu?>'); ?>	

The code <?=$page->type_menu?> is supposed to call a processwire field, but it doesn't work and processwire goes crazy, sending me a serious error message. Where do I go wrong?

Link to comment
Share on other sites

Use something like this:

<?php wireIncludeFile($page->type_menu); ?>	

What exactly do you have in the "type_menu" field?

You have to make sure that only your desired files can be accessed/included!


Perhaps it is also better to map this via a switch/case - perhaps an if is enough:

<?php
if($page->type_menu == "menu-A")
{
  wireIncludeFile('styles/menu-A.php');
}
else
{
  wireIncludeFile('styles/menu-B.php');
}
?>

 

  • Like 3
Link to comment
Share on other sites

  • 3 weeks later...
On 8/1/2023 at 3:27 PM, franciccio-ITALIANO said:

The code <?=$page->type_menu?> is supposed to call a processwire field, but it doesn't work and processwire goes crazy, sending me a serious error message. Where do I go wrong?

As you said: "<?=$page->type_menu ?> should call a Processwire field...".
But you want to include a page and not a field.

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...