vBulletin Mods

The Official vBulletin Modifications Site
https://www.vbulletin.org/forum/showthread.php?t=326851

Accessing Database Value from a Template.
by TransAmDan
26 Oct 2018 10:19

I want to access a database value from a VB template. The template is shown below. I have a new field in the 'attachment' table, called 'external_source' by default this will be zero, but if it is a 1, I want to produce different HTML code.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Looking inside album.php I have modified the call to the database to include this field too.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

So now $pictures contains the information from that database query.

Each individual pictures is fetched from
while ($picture = $db->fetch_array($pictures))

So in the template code I would expect pictures.external_source to contain the data from the database. Something isn't working right.

Is there some other process it goes through to pass data from album.php to the 'album_picturebit' template?

x iJailBreak x 29 Oct 2018 12:18

Quote:

Originally Posted by TransAmDan (Post 2597007)
I want to access a database value from a VB template. The template is shown below. I have a new field in the 'attachment' table, called 'external_source' by default this will be zero, but if it is a 1, I want to produce different HTML code.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Looking inside album.php I have modified the call to the database to include this field too.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

So now $pictures contains the information from that database query.

Each individual pictures is fetched from
while ($picture = $db->fetch_array($pictures))

So in the template code I would expect pictures.external_source to contain the data from the database. Something isn't working right.

Is there some other process it goes through to pass data from album.php to the 'album_picturebit' template?

If you do var_dump($pictures), what is the output?

Also, as a rule of thumb, it's best not to modify the core files - you should be able to utilize $hook_query_fields with the nearest hook to avoid making core changes to the code. Making core changes to the vB codebase is inadvisable as it can make it more difficult to upgrade, and usually means after upgrading the same changes need to be carried out again.

TransAmDan 29 Oct 2018 13:20

Thanks for the response, much appreciated.

Where would i put the var_dump? in the Template? I have tried a few different formats, but either get an error or no output.

{vb:raw var_dump($pictures)}

{vb:var_dump($pictures)}

x iJailBreak x 02 Nov 2018 22:01

Quote:

Originally Posted by TransAmDan (Post 2597080)
Thanks for the response, much appreciated.

Where would i put the var_dump? in the Template? I have tried a few different formats, but either get an error or no output.

{vb:raw var_dump($pictures)}

{vb:var_dump($pictures)}

Put it in album.php just after you run the query associated with $pictures.

Might also be worth putting exit after it too, so the var_dump is the only output.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I assume you are testing this on a different environment than live?


All times are GMT. The time now is 05:12.

Powered by vBulletin® Version 3.8.12
Copyright © 2019, MH Sub I, LLC dba vBulletin. All Rights Reserved. vBulletin® is a registered trademark of MH Sub I, LLC
Copyright ©2001 - , vbulletin.org. All rights reserved.