[英]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;拜托,我有使用条款页面,我想使用 laravel 和这样的商店名称播种;
'<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.所以我希望它显示为: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. Laravel 使用 php 刀片模板,因此如果您想将来自数据库的代码仅打印为文本,则可以使用此方括号
{{ }}
。 and if you have multiple line text or you have html code in database and you want to print it you can use {!! !!}
如果您有多行文本或数据库中有 html 代码并且您想打印它,您可以使用
{!! !!}
{!! !!}
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:如果您想在本机 php 代码中打印它,请使用:
<?= core()->getCurrentChannel()->business_name ?>
Note: Make sure you are fetched data from controller currently by print data coming from database using
print_r()
to beprint_r(core()->getCurrentChannel())
if it's not getting data recheck your code again.注意:确保您当前从 controller 获取数据,如果它没有获取数据,则使用
print_r()
将来自数据库的打印数据打印为print_r(core()->getCurrentChannel())
如果它没有获取数据,请再次重新检查您的代码。
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>
我将我的 html 代码播种如下
<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);
在我的 controller 我执行此操作
$pageContent = str_replace('{Name}', core()->getCurrentChannel()->business_name, $page->page_content);
then in my blade, I can access $pageContent
with {!!然后在我的刀片中,我可以使用 {
$pageContent
$pageContent !!} $页面内容!!}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.