BEIJING — The boy in the gray uniform yelled a heartfelt cry: “Although we are young, we are an unyielding Little Red Army!” he told his pint-size comrades. “I believe that as long as we are united, there is no difficulty that cannot be overcome.”

The scene was not from a 1930s-era drama on China’s equivalent of the History Channel. It was a play staged this month by pupils of Dengshikou Elementary School, at the China National Theatre for Children in Beijing.

Later in the show, called “Little Red Army,” the students sang: “Lifting my head, I see the Big Dipper, deep in my heart, I miss Mao Zedong . . .”

Performers ranging from kindergartners to university students are acting out themes of patriotism, traditional Chinese culture and core socialist values during three weeks of performances in the capital.

The program is part of a broader effort by the ruling Communist Party, accelerated under the leadership of Xi Jinping, to instill nationalist fervor in young Chinese and grow a whole generation loyal to him.

“Patriotic education is a fundamental part of education,” said Gao Xiaomei, who had brought her 9-year-old daughter to see the performance. “Kids should learn these kinds of lessons from the bottom of their hearts while they are very little.”

Her friend Zhang Meili, whose daughter is also 9, chimed in. “If kids don’t love their country, then how can they love their parents?” she asked. “I think the country has provided a really good education system. China is so advanced today.”

Such sentiments are widespread in China.

Now, as the Communist Party struggles to respond to months of protests in Hong Kong against China’s creeping control, it has decided that the city’s young people need some of this fervor. After encountering stiff resistance to a previous attempt to introduce patriotic education in Hong Kong schools, it plans to try again.

“We will strengthen national education for Hong Kong and Macao people, especially civil servants and youth . . . to boost their national consciousness and patriotic spirit,” Shen Chunyao, a top party official, said after a conclave last month, as the protests in Hong Kong raged.

That resolve is only likely to strengthen after voters in Hong Kong delivered a rebuke to Beijing in local elections last weekend, when pro-democracy candidates captured more than 80 percent of seats.

Since the foundation of the People’s Republic in 1949, China has promoted its particular flavor of Communist ideology through public institutions.

The endeavor took on a new dimension after the Tiananmen Square uprising in 1989, when millions of Chinese took to the streets to call for greater freedoms, and the collapse of the Soviet Union. China’s leaders began promoting patriotic education to instill national pride and loyalty to the party in younger generations.

These efforts have accelerated in the seven years since Xi took control of the party. He has turbocharged historical interpretations that portray China as the victim of cruel Western and Japanese enemies. Throughout the trade war with the United States, authorities have characterized the Trump administration as hellbent on stopping the Chinese rejuvenation envisioned in Xi’s “Chinese dream.”

“Thought work” begins in kindergarten, when 5-year-olds play games such as “My Country Is a Garden” to cultivate patriotic spirit, and sing nationalistic anthems such as “Me and My Motherland.” Children take field trips to museums commemorating the foundation of the party and the victory over imperial Japan.

The Chinese government issued new instructions this summer for teaching elementary and middle school students “to love the party, the country, socialism and the people.” Then it announced plans in August to make Xi Jinping Thought, the authoritarian leader’s guiding philosophy, a mandatory social science course in high schools.

Special attention is paid to universities, given students’ role in spearheading the 1989 protests. They are now subject to ideological education focused on “building loyalty to the party and passing on the heritage of socialism,” according to the official outline. Some 30 universities, governments and ministries host research institutes dedicated to the study of Xi Jinping Thought.

Chinese authorities believe that three decades of patriotic education have been remarkably successful in molding a generation of loyal citizens, analysts say.

An influential cohort of Chinese Internet users are so nationalistic they will castigate an NBA manager or fashion labels into apologizing for any perceived insult to China. They have also shown disdain for their pro-
democracy peers in Hong Kong.

“I think the Chinese propaganda machine is doing quite well with what we call the ‘rioters’ in Hong Kong,” said a Chinese academic who spoke on the condition of anonymity to discuss the sensitive situation. “People in Guangzhou, Beijing, Shanghai, people are not sympathetic to Hong Kong.”

Encouraged by this success on the tightly controlled mainland, the party is planning another attempt to export a version of this curriculum to Hong Kong — where concerns over the erosion of free speech and relative political freedoms underpin a widening backlash against Beijing.

It is focusing more on “one country” than on “two systems.”

“What’s happened in Hong Kong in recent months has been a big surprise to leaders in China, so they’re trying to find out the reason why Hong Kong became so anti-China or so anti-Chinese government,” said Zheng Wang, a Seton Hall University professor who specializes in identity and nationalism.

“They believe that because the people, especially the young people, in Hong Kong never received patriotic education, they lack this kind of national identity,” Wang said. “But Hong Kong is totally different to China, so I believe they will encounter very strong resistance, just like in 2012.”

Beijing’s last attempt, seven years ago, backfired spectacularly. A quarter-century after Britain returned Hong Kong to China, Beijing tried to introduce lessons to foster greater appreciation of mainland China and promote the Communist Party as a “progressive, selfless and united ruling group.”

The plan sparked vociferous protests, and Beijing was forced to back down.

Since then, Beijing has proceeded almost by stealth, encouraging study trips to the mainland and promoting Mandarin language learning in the Cantonese-speaking territory. But most analysts do not expect any new effort to be any more successful this time.

“I think any kind of mainland-style patriotic education is unlikely to succeed at winning hearts and minds in Hong Kong,” said Jessica Chen Weiss, an expert on Chinese nationalism who teaches at Cornell University.

If anything, the combination of a new effort at patriotic education and continued demonstrations against China’s encroachment is likely to provoke more resistance, she said.

“This would seem to be fueling that sense that Hong Kongers’ identity is under threat,” Weiss said.

The Chinese government has two options for making the people of Hong Kong view the mainland more favorably, said Brian Fong, a social scientist at the Education University of Hong Kong.

“One is to make Chinese identity more attractive,” he said. “To do so, China should be more open, more liberal so as to make the Hong Kong young people think the Chinese system isn’t that bad.”

The second option is to step up control over schools and the media, to manage messaging in Hong Kong as the party does in the mainland.

“But that’s also very difficult, because Hong Kong must maintain a sufficient degree of freedom in order to maintain its position as an international financial center,” Fong said.

Even some in the Chinese establishment see difficulty ahead.

“We have almost eliminated dialects in China, but Hong Kong is different,” the mainland academic said. “They still speak and use Cantonese. If we can’t even change their language, how will we change their mind-set?”

Liu Yang contributed to this report.