amp-mustache is not binding the amp-list response if template is loaded from react
Hello All,
I have few AMP Pages implemented using plain HTML and AMP components. And we are looking to host them in Node/React.
We are trying to use react's fs and res.send to load the page in react. The template is picked up and loading but, amp list's response is not binding to the page (And the response is loaded successfully to the browser).
I suspect this is because amp-mustache is not working because it is loaded from react and react is treating the mustache tags as its own variable's...
Can anyone help here,
Thanks, Vamshi
That may well be the issue, view source on the amp page will show if you are correct. If that is the issue it's not really an AMP issue as react is breaking your AMP page before the AMP runtime gets to it.
Thanks @jpettitt I'm looking after doT js for solution. Please share me any example links with AMP + doT + React if you know.
Greetings..!!! It worked well with ejs. Rendering the template using Node's express module instead of React.
Below is the code,
var url = require('url');
var express = require('express');
var app = express();
var server = app.listen(3000);
app.get('/amp', function(req, res) {
var productCode = 'MP000000014231';
var productDataAPI = 'https://api.myjson.com/bins/jgk2a';
var canonicalUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
console.log(canonicalUrl);
var data = {
productId : productCode,
productData : productDataAPI,
canonicalUrl : canonicalUrl
};
res.render('pdp_layout.ejs', data);
});
app.set('view engine', 'ejs');
And I can use/bind the variables in my html as below,
<%= productId %>
<%= productData %>
<%= canonicalUrl %>
Hope this might help others and closing the issue as it is resolved.