簡體   English   中英

如何在{{:example}}中搜索和替換內容

[英]How search and replace content inside {{:example}}

如果位於以下內容中,則可以找到替換頁面上的所有內容的方法:{{:replace_this}}

<a href="#">{{:main_link}}</a>
<div>{{:some_content}}</div>
<p>{{:body_text}}</p>

以:結尾

<a href="#">Home</a>
<div>Header 1</div>
<p>This is a body content</p>

我希望使用查詢和PHP做到這一點,具體取決於值,我可以更改此內容:

var X = [{main_link: "Home"},{some_content: "Header 1"}];
var Y = [{main_link: "Welcome"},{some_content: "Header 2"}];
var selector = true;
if(selector){
// change {{:this}} with X values
}else{
// change {{:this}} with Y values
}

這樣,然后使用以下方法渲染值:

$("body *").each(function(){
   $(this).html(value);
});

只是一個主意。

是的,你可以做到。

使用占位符保存HTML文件,然后像這樣在php中進行檢索:

$html = file_get_contents('/var/www/mywebsite.com/htdocs/html.html');

然后構建一個搜索詞數組:

$search = array('{{:main_link}}', '{{:some_content}}', '{{:body_text}}');

其中一個替換條款:

$replace = array($main, $content, $body);

然后執行switcheroo:

echo str_replace($search, $replace, $html);

在javascript中,您可以將元素添加到#id或.class(用於組元素),以html為目標,在PHP上下文中,我們可以討論細枝語法。

var value = ["Home", "Header 1", "This is a body content"];
var i = 0;
$("#title_page, #content_page, #paragraph_page").each(function(){
   $(this).html(value[i]);
  i++;
});

https://codepen.io/anon/pen/EwmywJ?editors=1111

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM