Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass PHP variable to Jade.PHP

Tags:

php

pug

I have a Jade template, and I want to pass a PHP variable $str into this template and show it. So in the template I put

{{$str}}

and then it got rendered like:

<title><?php echo $str ?></title>

I want the $str to be shown directly. But it's not mentioned in the node.php page.

Search online, there's some method like

eval("?>".$rendered."<?php");

and I believe this is a dirty solution because if my template has something like "?>" then everything would be wrong.

Is there a proper way of doing this thing?

like image 443
songyy Avatar asked Jan 22 '26 22:01

songyy


1 Answers

Compile the template, store it in a .php file. Recompiling a file everytime you need it is a bad idea :). I'd recommend using a md5file (or just md5 the file's content) to know if a file changed or not, and recompiling it on-the-fly.

and then just include it.

like image 126
Ven Avatar answered Jan 24 '26 12:01

Ven



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!