Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom template variable #412

Open
Pok4 opened this issue Apr 18, 2023 · 2 comments
Open

custom template variable #412

Pok4 opened this issue Apr 18, 2023 · 2 comments

Comments

@Pok4
Copy link

Pok4 commented Apr 18, 2023

Hello,
i have this php function:

function get_from_db_config($val) {
	global $dbh;
	$get = $dbh->query("SELECT ".$val." FROM ".$_SERVER['DB_PREFIX']."config");
	$row = $get->fetch(PDO::FETCH_ASSOC);
	return $row[$val];
}

It is possible to have template variable (custom) to fetch data from table name -> column name, like this:
{{get_from_db | tablename | columnname}}
?

Something like that will be very good solution for me... I fetch mostly int values from columns, but sometimes there is a text too..
If you know a method or workaround to do that, i'll be very happy :)

@bobthecow
Copy link
Owner

it's not really idiomatic mustache to made database calls from the template. you should prepare your data before rendering, or use a viewmodel to encapsulate the logic.

@Pok4
Copy link
Author

Pok4 commented Apr 22, 2023

Yes, im agree with you, but can you give me example with ready to use code ?
Now im using this - #392
If is possible with something like this, will be ok for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants