簡體   English   中英

快遞車把模板不會呈現部分

[英]express handlebars template wont render partial

這個問題讓我幾乎郁悶..
不久前,整個應用程序運行正常,但最近(可能超過 3 個月,也許 6 個月)我的一條路線拒絕渲染我通過它的任何車把模板,包括通過其他路線成功渲染的車把模板。

這是違規路線:

app.get('/ListContentItems', function (req, res, next) {

  try{
    getAuthToken().then(authToken =>{
      axios({
        method:"get",
        // url: "https://"+cmsEnvironment+"/content-repositories/"+respositoryId+"/content-items?page="+req.params.page+"&size="+req.params.size,
        url: "https://"+cmsEnvironment+"/content-repositories/"+respositoryId+"/content-items?page=0&size=2",
        headers:{
          "Authorization": "Bearer " + authToken
        }
      })
        .then(response => {
          var contentGraph = response.data;
          var stringContent = JSON.stringify(response.data,null,'\t');
          console.log(stringContent);
          res.render("list-content-items",{
            static_path:'/static',
            theme:process.env.THEME || 'flatly',
            pageTitle : "List Content Items",
            pageDescription : "List Content Items",
            reqParams : req.query,
            contentGraph : contentGraph._embedded,
            stringContent : stringContent
          })
          // res.render('list-content-items',{static_path:'/static','pageTitle':'List Content Items - Success','contentGraph': contentGraph._embedded, 'stringContent' : stringContent, 'reqParams': req.query});
        })
        .catch(error => {
          console.log(error);
          res.render('list-content-items',{'pageTitle':'List Content Items - Fail','reqParams': req.query, 'error':error});
        });
    })
    .catch(error => {
      console.log(error);
      next(error);
    })

    }
  catch (e) {
    next(e)
  }


/* res.render('list-content-items',{title:"List Content Items",error:"figure out how to authorize so that i can list the content items and create links.."}) */

})

這是模板:

{{> header }}
{{#each contentGraph }}

  {{#each this}}
      {{log this}}
      {{this.id}}

      {{#each this}}
        
        {{#if (eq this._meta.schema 'http://www.coops.net/draping-config')}}
          <a href="/draping?id={{this.id}}&store=bccdemo">{{this.label}}</a><br />
        {{else if (eq this._meta.schema 'http://c1-qa.adis.ws/c/cmslabs/content-stack')}}
          <a href="/panels?id={{this.id}}&store=bccdemo">{{this.label}}</a><br />
        {{else}}
          <a href="/?id={{this.id}}&store=bccdemo">{{this.label}}</a><br />
        {{/if}}
        
      {{/each}}
  {{/each}}
</div>
{{/each}}

{{> footer }}

這是日志 output:

{ id: '3fae61b6-56ef-4c31-9c53-40f45131b435',
  contentRepositoryId: '5c5c64adc9e77c0001d73a22',
  folderId: null,
  body:
   { _meta:
      { name: 'Image Block 2',
        schema: 'http://c1-qa.adis.ws/c/cmslabs/image-block' },
     image:
      { _meta: [Object],
        id: 'b7a1bced-e921-42ab-baef-b5aa43cd3701',
        name: 'Fashion_Womens_Collection_SSS',
        endpoint: 'bccdemo',
        defaultHost: 'i1.adis.ws' },
     editorial:
      { callToAction: [Object],
        useParentAsCtaHotspot: false,
        title: 'This coat is far too big',
        text: 'but it\'s trendy',
        overlayAlignment: 'Top Left',
        overlayTheme: 'Darken',
        alignCopyText: 'center' },
     aspectRatio: { w: 4, h: 3 } },
  version: 1,
  label: 'Image Block 2',
  status: 'ACTIVE',
  createdBy: '2f38a1a9-c76d-4f34-91fa-652d09b6eede',
  createdDate: '2020-08-11T13:45:50.420Z',
  lastModifiedBy: '2f38a1a9-c76d-4f34-91fa-652d09b6eede',
  lastModifiedDate: '2020-08-12T19:39:12.261Z',
  lastPublishedVersion: 1,
  lastPublishedDate: '2020-08-12T19:39:11.301Z',
  deliveryId: '3fae61b6-56ef-4c31-9c53-40f45131b435',
  _links:
   { self:
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435' },
     'content-item':
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435{?projection}',
        templated: true },
     publish:
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435/publish' },
     planned:
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435/planned{?epoch,time}',
        templated: true },
     update:
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435' },
     'restore-version':
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435/restore' },
     'content-repository':
      { href:
         'https://api.amplience.net/v2/content/content-repositories/5c5c64adc9e77c0001d73a22' },
     'content-item-version':
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435/versions{/version}',
        templated: true },
     'content-item-versions':
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435/versions{?page,size,sort}',
        templated: true },
     'content-item-history':
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435/history{?page,size,sort}',
        templated: true },
     copy:
      { href:
         'https://api.amplience.net/v2/content/content-repositories/{id}/content-items?sourceContentItemId=3fae61b6-56ef-4c31-9c53-40f45131b435',
        templated: true },
     unarchive:
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435/unarchive' },
     archive:
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435/archive' },
     'set-locale':
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435/locale' },
     'create-localizations':
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435/localize' },
     localizations:
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435/localizations{?page,size,sort}',
        templated: true },
     'localization-jobs':
      { href:
         'https://api.amplience.net/v2/content/localization-jobs/search/findByRootContentItem?id=3fae61b6-56ef-4c31-9c53-40f45131b435{&page,size,sort}',
        templated: true },
     'edition-slot-associations':
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435/edition-slot-associations' },
     'edit-workflow':
      { href:
         'https://api.amplience.net/v2/content/content-items/3fae61b6-56ef-4c31-9c53-40f45131b435/workflow' },
     'content-item-with-children':
      { href:
         'https://api.amplience.net/v2/content/content-items/search/findByIdWithChildren?id=3fae61b6-56ef-4c31-9c53-40f45131b435' } } }
{ id: '66436a40-eea3-414e-9036-98580220787a',
  contentRepositoryId: '5c5c64adc9e77c0001d73a22',
  folderId: null,
  body:
   { _meta:
      { name: 'draping---sofa',
        schema: 'http://c1-qa.adis.ws/c/cmslabs/draping-demo' },
     SVG:
      { _meta: [Object],
        id: '1200180d-7332-4228-8e88-1919906e44b8',
        name: 'test_sofa',
        endpoint: 'bccdemo',
        defaultHost: 'i1.adis.ws' },
     Textures: [ [Object], [Object], [Object] ] },
  version: 1,
  label: 'Draping - Sofa',
  status: 'ACTIVE',
  createdBy: '2f38a1a9-c76d-4f34-91fa-652d09b6eede',
  createdDate: '2019-03-12T23:20:41.925Z',
  lastModifiedBy: '2f38a1a9-c76d-4f34-91fa-652d09b6eede',
  lastModifiedDate: '2019-03-12T23:20:41.925Z',
  deliveryId: '66436a40-eea3-414e-9036-98580220787a',
  _links:
   { self:
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a' },
     'content-item':
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a{?projection}',
        templated: true },
     publish:
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a/publish' },
     planned:
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a/planned{?epoch,time}',
        templated: true },
     update:
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a' },
     'restore-version':
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a/restore' },
     'content-repository':
      { href:
         'https://api.amplience.net/v2/content/content-repositories/5c5c64adc9e77c0001d73a22' },
     'content-item-version':
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a/versions{/version}',
        templated: true },
     'content-item-versions':
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a/versions{?page,size,sort}',
        templated: true },
     'content-item-history':
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a/history{?page,size,sort}',
        templated: true },
     copy:
      { href:
         'https://api.amplience.net/v2/content/content-repositories/{id}/content-items?sourceContentItemId=66436a40-eea3-414e-9036-98580220787a',
        templated: true },
     unarchive:
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a/unarchive' },
     archive:
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a/archive' },
     'set-locale':
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a/locale' },
     'create-localizations':
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a/localize' },
     localizations:
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a/localizations{?page,size,sort}',
        templated: true },
     'localization-jobs':
      { href:
         'https://api.amplience.net/v2/content/localization-jobs/search/findByRootContentItem?id=66436a40-eea3-414e-9036-98580220787a{&page,size,sort}',
        templated: true },
     'edition-slot-associations':
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a/edition-slot-associations' },
     'edit-workflow':
      { href:
         'https://api.amplience.net/v2/content/content-items/66436a40-eea3-414e-9036-98580220787a/workflow' },
     'content-item-with-children':
      { href:
         'https://api.amplience.net/v2/content/content-items/search/findByIdWithChildren?id=66436a40-eea3-414e-9036-98580220787a' } } }

這是視覺上出現的內容: 視覺輸出

和 HTML output:

<!doctype html>
<html lang="en">
  <head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="Amplience Demo: List Content Items">
    <meta name="author" content="">
    <meta http-equiv="Accept-CH" content="DPR,Width,Viewport-Width">

    <title>Amplience Demo - List Content Items </title>

    <!-- Bootstrap core CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="/static/css/custom.css"/>



  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
          <a class="navbar-brand" href="/?id=&store=">
            <span class="d-lg-block d-none">Amplience - Content Simplified</span>
            <span class="d-block d-lg-none">Amplience</span>
          </a>
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
    
          <div class="collapse navbar-collapse" id="navbarsExampleDefault">
            <ul class="navbar-nav mr-auto">
              <li class="nav-item dropdown"><a class="nav-link" href="/showJSON?id=&store=">ShowJSON</a></li>
              <li class="nav-item"><a class="nav-link" href="/carousel?id=&store=">Carousel</a></li>
              <li class="nav-item"><a class="nav-link" href="/panels?id=&store=">Panels</a></li>
              <li class="nav-item"><a class="nav-link" href="/ListContentItems/5/1">List Content Items</a></li>
            </ul>
          </div>
        </nav>
    
        <main role="main" class="container">





    </main><!-- /.container -->
        
    
    
        <!-- Bootstrap core JavaScript
        ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->
    
    
        <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>  </body>
</html>

我認為很明顯模板的主體根本沒有呈現。

但其他更復雜的路線按預期呈現..

如果您需要更多信息,請告訴我。

在開始了一個全新的項目並將這條路線拉進去之后,我有了片刻的啟蒙——這是任何遇到類似問題的人的答案:

我使用的是快速車把 package,它的布局默認為 main.hbs。

我在那里寫了一堆條件(反射時有點菜鳥錯誤),這阻止了身體的渲染——一定是有點僥幸,只有這條路線被打破了。

教訓:如果您使用 express-handlebars,請不要在 main.hbs 文件中添加任何復雜的邏輯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM