简体   繁体   中英

How to display php code in html page dynamically

Please, I have terms of use page and I want to seed using laravel with the store name like this;

'<p>Welcome to <?php printf(core()->getCurrentChannel()->business_name) ?>. We reserve the right... </p>

So I want it to display like this: Welcome to ufanstore. We reserve the right...

The store name can change if the admin rename his/her store name. my question is how can I display this so that it can change dynamically?

Laravel use php blade template so you can use this brackets {{ }} if you want to print code coming from database as text only. and if you have multiple line text or you have html code in database and you want to print it you can use {!! !!} {!! !!} in your example you can use the below code

<p>Welcome to {{core()->getCurrentChannel()->business_name}} . We reserve the right... </p>

and if you want to print it in native php code use:

<?= core()->getCurrentChannel()->business_name ?>

Note: Make sure you are fetched data from controller currently by print data coming from database using print_r() to be print_r(core()->getCurrentChannel()) if it's not getting data recheck your code again.

In case any one need, I resolved my issue with the following approach;

I seeded my html code like this <p>Welcome to {Name}. We reserve the right to update or modify these Terms of Use at any time without prior notice</p> <p>Welcome to {Name}. We reserve the right to update or modify these Terms of Use at any time without prior notice</p>

in my controller I perform this action $pageContent = str_replace('{Name}', core()->getCurrentChannel()->business_name, $page->page_content);

then in my blade, I can access $pageContent with {!! $pageContent !!}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM