Express Handlebars for Breaking the Meta Tag Strings in JavaScript

I am currently using Express with Handlebars as the template engine to render meta tags dynamically. Below is the script I have implemented:

var express = require("express");
var prerender = require("prerender-node");
var app = module.exports = express();
var handlebars = require("express-handlebars");

app.engine("handlebars", handlebars({defaultLayout: "main"}));
app.set("view engine", "handlebars");

app.use(prerender.set("prerenderToken", "qi2e5B985PptQE8aF0dt"));
app.use(express.static("./"));
app.get("/", function (req, res) {
    // res.sendFile("./index.html");
    res.render("home", {
        title: "PLUNQ",
        metaKeyword: "temukan dan ciptakan perjalananmu sendiri, create trip, create diary, follow trip, hidden places, aplikasi untuk traveller",
        metaDescription: "Temukan dan ciptakan perjalananmu disini, Situs yang menyediakan rujukan tempat menarik, event, penginapan serta produk lokal",
        ogTitle: "Plunq | Temukan dan ciptakan perjalananmu disini",
        ogUrl: "https://plunq.id/",
        ogDescription: "Temukan dan ciptakan perjalananmu disini, Situs yang menyediakan rujukan tempat menarik, event, penginapan serta produk lokal",
        ogImage: "https://plunq.id/images/og-image.jpg",
    });
});

app.listen(1234);

Additionally, here is my Handlebars code:

    <title>{{title}}</title>
    <meta name="keywords" content={{metaKeyword}}>
    <meta name="description" content={{metaDescription}}>
    <!-- og meta start here -->
    <link rel="canonical" href={{ogUrl}}/>
    <meta property="og:title" content={{ogTitle}}/>
    <meta property="og:url" content={{ogUrl}}/>
    <meta property="og:type" content="website"/>
    <meta property="og:description" content={{ogDescription}}/>
    <meta property="og:image" content={{ogImage}}/>
    <meta property="fb:app_id" content="921046191363161"/>

After passing the og and meta properties to my template, I encountered an issue where it breaks the meta tags when viewed in the browser, displaying incorrectly like this: https://i.sstatic.net/B14fm.jpg

Any suggestions on how I can resolve this issue?

Answer №1

Remember to always enclose content in quotation marks (")

<meta name="description" content="{{metaDescription}}">

This is a key aspect of the HTML 4.01 specification

In HTML, attribute values should be surrounded by either double quotes (ASCII decimal 34) or single quotes (ASCII decimal 39). If necessary, single quotes can be used inside a value enclosed by double quotes, and vice versa.

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

Is it possible to utilize $(document).ready() within an ASP.NET page?

I am encountering an issue while attempting to use $(document).ready() as shown in the image above. What steps should I take to troubleshoot and resolve this problem? Update 23/05/2011 10:54 A new insight has come to light. The page I am working on inher ...

How to locate and extract specific data from a webpage table using JavaScript and Node.js for web scraping and storing in an array of objects

Exploring the realm of web scraping by targeting a UFC betting site for data extraction. JavaScript, alongside request-promise and cheerio packages, is utilized in this endeavor. Site: The primary aim is to retrieve the fighters' names along with th ...

Importing a file using its absolute path in JavaScript

Within the dependencies directory, there exists a module named foo: import foo from '../dependencies/foo'; // This import statement works as intended The challenge arises when attempting to import from a different path due to deployment in an AW ...

Implementing basic authentication for an Express REST API

I have a REST API where user data is stored in MongoDB. I am looking to implement basic authentication for my API, but I am facing some challenges. I want to check if a user is authorized on certain paths, such as /update. If the user is authorized, the re ...

What is the best way to design a new class that will serve as the parent class for both of my existing classes, allowing them

I am facing a challenge with my programming classes. I have two classes, "Player" and "Enemy", each with similar methods and properties. I want them to inherit from a parent class that I'll create called "Game Object". How can I approach creating thi ...

Using React Material UI icon within an auto complete feature

https://i.stack.imgur.com/W3CmF.png I am struggling to incorporate the target icon into the autoComplete component. After reviewing the documentation, I have been unable to find a solution. In TextInput, a similar outcome can be achieved by implementing ...

Why doesn't jQuery ajax work when sourcing the URL from a variable but works with a hard-coded URL?

During my experimentation with setting and getting the URL for a jQuery Ajax (post) call, I realized the value of dynamically setting the destination URL for the request. Here's how I attempted to achieve this: To set the URL to 'store.php' ...

Determining the Presence of a Value in an Array using .includes

I've been facing challenges trying to use .includes with my array. My goal is to have a function that checks if a value already exists and removes it from the array if it does. The value is a string obtained from an object with a .name property. 0: { ...

What is the best way to animate a div sliding to the right, as if it is emerging from behind another div?

Alright, so I've got a div with multiple links in it. What I need is for all these links to trigger a sliding animation from the left side to the right within the same div. After my research, it seems like Jquery's animate function should be the ...

Transform Dates without using "T" or "Z" into Dates with a T-Z Format

I received a JSON file that contains dates in the format of 2021-09-21 15:37:29.590 +03:00. What is the best way to convert this date into a T-Z format? ...

Problem occurs when tab links vanish after clicking on another part of the website

Exploring the world of Javascript as a newcomer has been quite an adventure, but I've encountered a hurdle with tab links on my website. Everything seems to be working fine – the links cycle through and display the correct content. However, when it ...

Deactivate Bootstrap Button Pills and Activate Change with an Alternate Button

Seeking a solution for my multi-step form utilizing Bootstrap nav-pills. Currently, users can navigate through the steps without completing the required form fields first. I am looking to disable this feature and trigger content changes with a different bu ...

Reducing function name length by using a variable

Is there a way to reduce the size of my code by calling functions with shorter aliases? (function(){ var id = document.getElementById; id('element-id'); })(); After making this change, an error message appears: Error: Could not convert ...

Creating event listeners for slides transitioning forwards and backwards in Swiper JS: How can it be done?

Is there a way to create separate functions for when the slider moves forward and when it moves back? The documentation only mentions an event (slideChange) that triggers whenever the slide changes in any direction. If you have any suggestions or methods ...

JQuery malfunctioning after refreshing the page

As a newcomer to web development and jQuery, I am facing an issue with my aspx page that contains a RadioList with 3 items and 3 hidden divs. Upon post back, I am trying to show the selected div using jQuery, however, it doesn't seem to be working. C ...

Best practices for updating nested properties in Angular objects

I have a dataset that includes information about fruit prices for different years: { "fruits": [ { "name": "apple", "prices": [ { "2015": 2, "2014": 3, ...

Extract a selection from a dropdown menu in ReactJS

I have multiple cards displayed on my screen, each showing either "Popular", "Latest", or "Old". These values are retrieved from the backend. I have successfully implemented a filter option to sort these cards based on popularity, age, etc. However, I am u ...

What is the reason for AngularJS rendering boxes in a new row during loop iterations

I have a collection of items that I would like to showcase next to each other in rows. The static HTML code I have currently works perfectly. <div> <div class="box"></div> <div class="box"></div> <div class="b ...

Warning happens two times upon performing a right-click

I've got some code that checks the mouse's position, and triggers an alert followed by a redirect if a certain condition is met. It functions correctly, however, I noticed that if you right-click in one area and then left-click in another area t ...

AngularJS showcases the full spectrum of available methods

I am struggling to create a method for composing a URL in my class. Here is what I have attempted: The createLink method takes an ID and returns the corresponding URL: console.log("before the method"); console.log($scope.createLink ) $scope.createLink = f ...