Ad
How To Access Template Variables In The Script Section Of My HTML File In Google Apps Script?
I need to access templated variables in the script section of my HTML file. Specifically, I need to use content.price
.
I can access content.price
just fine in the templated section of the body of my HTML.
<div class="container">
Price: $<?= content.price ?></td>
<div id="paypal-button-container"></div>
</div>
But in the script section, trying to access content.price
seems to be throwing an exception.
amount: {
value: content.price // '0.01' // Using content.price throws an error
}
What am I doing wrong?
Code.gsvar template = HtmlService.createTemplateFromFile(HTML_FILENAME);
template.content = values;
var htmlOutput = template.evaluate();
index.html
<!DOCTYPE html>
<!-- source: https://developer.paypal.com/docs/checkout/integrate/ -->
<html>
<body>
<div class="container">
Price: $<?= content.price ?></td>
<div id="paypal-button-container"></div>
</div>
<script
src="https://www.paypal.com/sdk/js?client-id=SB_CLIENT_ID">
</script>
<script>
// This function displays Smart Payment Buttons on your web page.
paypal.Buttons({
createOrder: function(data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
amount: {
value: content.price // '0.01' // Using content.price throws an error
}
}]
});
},
}).render('#paypal-button-container');
</script>
</body>
</html>
Ad
Answer
In script section also you'll need to use template tags.
Something like these :
amount: {
value: <?!= content.price ?>
}
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad