I’m struggling with this for few hours, but I can’t get it to work properly. What I wanna do is find a line
<div id="content">
and add few lines below that contain some variables like
<div class="post">
<h2 class="title"><a href="#">**var**</a></h2>
<p class="meta"><span class="date">**var**</span>
<span class="posted">Posted by <a href="#">**var**</a></span></p>
<div style="clear: both;">
</div>
<div class="entry moreless">
**var**
</div>
</div>
Is it possible? If so how?
–David
There are much better tools available to solve this. But it is possible with Windows batch!
Assume the text below is the outermost template file named TEMPLATE.HTML. The content trigger line can be indented, but this solution does not allow extra characters after the trigger. (This limitation could be solved, but it would slow things down)
The sample content file below (named CONTENT_HTML.TXT) contains variables specified as !varName! and the batch file will use delayed expansion to perform the variable substitution. This means that if you want the content to contain an exclamation, it must be encoded somehow. There are two choices. One is to use the HTML character notation ! This works fine for text content, but will not work if you want an HTML comment. For comments I define an !X! variable that will be expanded to !
Finally here is a batch file that will put everything together and create an output file named FINAL.HTML. I hard coded the values for the variables, but they could just as easily be passed in as arguments.
There are some limitations with this solution