Using values from an appsettings.json file as href variables in an AMP html: a complete guide

Currently developing an AMP website with the URL www-dev.example.com, directing users to a sign-up page. The sign-up page is hosted on an identity server under the subdomain auth.www-dev.example.com.

Now, the goal is to deploy the AMP website to a staging environment using the URL www-stg.example.com, and simultaneously direct users to its corresponding staging identity server auth.www-stg.example.com.

The plan involves creating a config per environment within a relative appsettings.json file and utilizing amp-mustache to map the environment variables into the URLs of <button> or a tags.

While trying to achieve this functionality using amp-list, some issues have arisen, impacting the front end with alignment and scaling problems due to fixed dimensions that result in undesirable outcomes.

Is there a straightforward method to set environment variables in AMP for use in links?

Implementation in HTML:

<amp-list width="130" height="45" layout="flex-item" src="/appsettings.json">
 <template type="amp-mustache">
  <button type="button" on="tap:AMP.navigateTo(url='{{signup-url}}', target='_top')">Sign Up</button>
 </template>
</amp-list>

Implementation in appsettings.json:

{
    "items":[{
    "login-url":"https://auth.www-dev.example.com/login",
    "logout-url":"https://auth.www-dev.example.com/logout",
    "signup-url":"https://auth.www-dev.example.com/signup",
    "unsubscribe-url":"https://auth.www-dev.example.com/unsubscribe"
   }]
}

Any suggestions or assistance would be greatly appreciated!

Edit - Example demonstrating initial front end issues that I aim to avoid.

<!DOCTYPE html>
<html ⚡ lang="en">
<!-- Rest of the code remains unchanged from original text -->

Answer №1

For my project, I opted to utilize Terraform and integrate the html file as a template during deployment, before transferring the html to its intended hosting location.

Here is the HCL code snippet:

module "template_files" {
  source               = "hashicorp/dir/template"
  base_dir             = "./src/static_website"
  template_file_suffix = ".html"
  
  template_vars = {
    canonical  = var.canonical
    signup-url = var.signup-url
  }
}

And here is an example of how the HTML code looks:

<button type="button" on="tap:AMP.navigateTo(url='${signup-url}', target='_top')">Sign Up</button>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Provide alternative styling through css in instances where the Google Books API does not provide an image

How can I modify the CSS code to display the author and title of a book when there is no image available from the Google Books API? Currently, users see a custom image linked here, but it's not clear what it represents without the name and author inf ...

What is preventing relative paths from functioning with xsl:include?

I am working with an XSL file that converts to PDF. The top of the page contains a lengthy CSS style declaration: <xsl:attribute-set name="Header"> <xsl:attribute name="font-size"> <xsl:value-of select="$font-size"/> < ...

What about a lightbox with enhanced jQuery features?

As a newcomer to jQuery, I've never experimented with lightboxes before. However, I was tasked with creating something fun for April Fools' Day at work. Naively, I accepted the challenge thinking it would be simple, but now I find myself struggli ...

Each block in Svelte includes a unique shorthand attribute

I have a JSON variable that holds attributes in a specific structure: // This json variable defines the attributes for elements to be created let myElements = [ { attr1: "myAttr1", attr2: "myAttr2", }, { ...

Tips for concealing scrollbars across various browsers without compromising functionality

Is there a way to hide the scrollbar functionality on a horizontal scrollbar without using "overflow: hidden"? I need to maintain JS functionality and ensure compatibility with all modern browsers. $j = jQuery.noConflict(); var $panels = $j('#primar ...

Support for nesting span elements in HTMLDocument

Struggling to incorporate this specific text into my HTMLDocument: <html><span class='stuff' id='X'><span id='Y'>content</span></span></html> Utilizing the following code for insertion: S ...

How can you vertically center an icon button in Material UI?

Looking for help with aligning elements in this code snippet: <TextField id="outlined-basic" label="22Keyword" defaultValue={"test123"} variant="outlined" /> <IconButton aria-label="delete&q ...

The margin and width of a div element with the position set to fixed and display set to table-cell are not rendering correctly

Is there a way to keep my .nav-container position: fixed; without creating a gap between it and the .page-content at certain window widths? When I set the position to fixed, a small white line appears between the red background of the .nav-container and th ...

Steps to trigger an alert when the entered quantity exceeds the current stock levels

After developing an IMS System, I encountered a problem where my stock is going into negative figures. To resolve this issue, my primary goal is to trigger an alert whenever the quantity entered by a user exceeds the available stock. For example, if a us ...

Icon: When clicked, initiate a search action

I am looking to make the icon clickable so that it can be used as an alternative to pressing the "return key" for searching. Check out this bootply example at . You simply need to click on the magnifying glass icon and it will initiate the search. ...

Attempting to store the output of a function in a variable

My current script is designed to verify if the value of a selected element matches the span id. While the function itself functions correctly (verifying object.id via alert), I am encountering issues with variable assignment. When attempting to alert the ...

Error in zone: 140 - Property 'remove' is not readable

I'm brand new to kendo ui. I successfully set up a prototype in my fiddle with a working delete confirmation window. However, when I try to integrate it into my existing codebase, I encounter an error: Cannot read property 'remove' at the li ...

Creating CSS styles for mobile devices, such as smartphones and tablets

Hey there! I've been using CSS for developing desktop websites for quite some time now, and I'm eager to expand my skills to build websites that cater to a variety of devices like phones, smartphones, tablets, and even consoles with web browsers. ...

transferring background-image in html between elements

Imagine having a three-level hierarchy HTML code structured like this: <section> <div id="outer"> <div id="inner"> </div> </div> </section> If we set background-image:someImage.jpg to the section, and backg ...

Unable to run a Bash script using PHP

I'm currently facing a challenge while attempting to run a simple Bash Script from within a PHP script. The process involves collecting data from an interactive HTML5 front-end page, transmitting it through ajax to the PHP script, parsing the variable ...

When Css is incorporated within a text, it prevents the use of " " from functioning properly

I am currently developing a GUI application using Qt 4.8. I have a label that displays text in white (the stylesheet has already been set up for this) and I want to change the color of the word "UPDATE" to red. Here is my initial code: //all text in whit ...

The button is unable to contain all the text, causing it to spill out instead of wrapping to

Need help with creating an HTML button that opens a link. The button consists of a title and a short description, but when the description is too long, it overflows outside the button. Currently implementing bootstrap and jquery. Code: body { backgr ...

The subdirectory containing the Rails assets is causing loading issues in the production environment

My event CSS is currently located in app/assets/stylesheets/pages/events.scss. Surprisingly, everything looks perfect in development mode with all the assets loading properly. However, the real issue arises when I switch to production as it seems like thes ...

Ways to display content exclusively to logged-in users

Currently, I am working on a website and facing a challenge in displaying certain elements on the navbar only if the user is logged in. The structure of my project involves using inheritance, which means that the navbar is included in my layout.html file. ...

How to position the navigation bar to the right using bootstrap

I have been experimenting with moving the navigation bar to the right side of the screen in bootstrap4 by using float: right; on the nav a element, but it doesn't seem to be having any effect. I am developing my project using a codepen app. Here is t ...