Is possible find a replace everything on a page if this is inside something like this: {{:replace_this}}
Example
<a href="#">{{:main_link}}</a>
<div>{{:some_content}}</div>
<p>{{:body_text}}</p>
to end with:
<a href="#">Home</a>
<div>Header 1</div>
<p>This is a body content</p>
I hope to do this with query and PHP where depending on the value I can change this content:
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
}
Something like that and render the values using maybe:
$("body *").each(function(){
$(this).html(value);
});
Just an idea.
Yeah you can do that.
Save your HTML file with the placeholders in, then retrieve in in php like this:
$html = file_get_contents('/var/www/mywebsite.com/htdocs/html.html');
Then build an array of your search terms:
$search = array('{{:main_link}}', '{{:some_content}}', '{{:body_text}}');
And one of you replacement terms:
$replace = array($main, $content, $body);
Then perform the switcheroo:
echo str_replace($search, $replace, $html);
In javascript you can target you element html adding #id or .class (for groups elements), here in PHP context we can talk about twig syntax.
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++;
});
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.