Jump to content

Access $modules variable from within _init.php


Stefanowitsch
 Share

Recommended Posts

Hello!

I am using the _init.php file to place different php functions to render something on the page. For example a gallery, or a teaser group. 

I can then just call the function within a page template and the function renders the HTML code with the data given.

Right now I want to render some teasers but I need to have access to the $modules variable which is not working right now. I get an undefined variable error. 

How can I use the $module variable in a different environment than a template file?

Link to comment
Share on other sites

26 minutes ago, Stefanowitsch said:

Right now I want to render some teasers but I need to have access to the $modules variable which is not working right now. I get an undefined variable error. 

You are getting hit by a variables scope issue. You cannot use global variables like $modules directly inside a function. Instead, use this (there are other variants - see the new docs here)

wire('modules');

 

Edited by kongondo
  • Like 4
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...