Erya Van Achterndyk
Erya Van Achterndyk

Reputation: 41

How can I use "Variables" in php, which are created by "str_replace" and "array"also in Javascript?

I use in my HTML Markups always Underlines, which are programmed with PHP and will replaced by strings. For example:

<title>__TITLE__</title>

So in this way I have just one template of HTML but my pages although have their own title names.

But in one case I have a problem. I also use JQuery and I have this case:

$("div").append("<p>__NAME__</p>");

In this case there is the text "__NAME__" on my Homepage, not e.g. "John".

Can someone help?

Upvotes: 0

Views: 57

Answers (1)

trincot
trincot

Reputation: 350272

You could add a placeholder div for it in your HTML:

<div id="template1" style="display:none">__NAME__</div>

Then in your code, pick up the contents of that element (which will have been altered by PHP):

$("div").append($("<p>").html($("#template1").html()));

Upvotes: 1

Related Questions