I need some help echoing some $variables in the index.template.php

Started by rcane, April 01, 2023, 01:38:48 PM

Previous topic - Next topic

rcane

2.0.19

I've got a php page that runs a few queries and has a couple of variables as a result.

I was trying to echo the variables in the index-template.php in the area kind of set aside for that stuff, below the main above area.

If I try to include/require the stuff.php file, I get 'call to member function query() on NULL.

I know the variables work, as I've tested that.  So, am I including improperly?


include('/home/example.com/files/stuff.php');



Kindred

Do note that database queries do not belong in the display templates
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

rcane

Quote from: Kindred on April 01, 2023, 02:08:46 PMDo note that database queries do not belong in the display templates

the query wasn't in the template, if that's what you meant. 

the stuff.php had the connection/query/and stored variables in it. 

if I echo inside stuff.php and run that it shows the queries work (just ->num_rows calls).

If I include stuff.php that's when it gives the error.


rcane

I've checked the queries and they do not return null.

for example:
$GETdateun = $connltd->query("

SELECT *  FROM ltd_themes
WHERE `variable` = 'cust_dateun'
AND `value` REGEXP '^[0-9/-]+$'
AND LENGTH(`value`) > 0 ");

   
$final_dateun = ($GETdateun !== NULL) ? $GETdateun : 0;


Kindred

This is why you'd load things to the $user_info or $context variable arrays...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

rcane

Quote from: Kindred on April 01, 2023, 02:47:04 PMThis is why you'd load things to the $user_info or $context variable arrays...

I've not had a need like this before.  Can you point me in the direction to add a those few variables so they're displayable?

Arantor

To display them in index.template.php you need to load them on every page, which means editing the core files so that your code runs every page. Hard to know where the correct place for that is.

As for putting the values into $context, it's really no more complex than making sure your code calls 'global $context' to pull it into correct scope, then just $context['final_daterun'] = ($GETdateun !== NULL) ? $GETdateun : 0; or similar.

rcane


Doug Heffernan

Why not put in some extra work and do it properly by making a mod out of it? It will be worth the while imo.

You can use the integrate_pre_include hook to load/call/include your custom php file, which should be uploaded inside the /Sources directory. You can also create another template file to hold the display stuff.  This file should be uploaded inside /Themes/default folder.

Then you can use the integrate_load_theme hook for the query and to register the variable for use in the custom template. You can control the display place with a conditional inside the function that calls the integrate_load_theme hook.

Advertisement: