We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23217
    • 44 Posts
    I am trying to display the meta tag for "author" in my ditto line for documents (rather than the creator of the page; for me they are different). I have a snippet that gets the meta tag author and sets a placeholder [+meta-author+] with the correct data. I can call the snippet as [[GetAuthor]] in my ditto template, and that produces an author, but does not produce the correct author for each page (I believe, because it is cached it only gets it the first time). I tried using [!GetAuthor!] in all the ways I could think of, but all I end up with is the literal string ’[!GetAuthor!]’ in my author line.

    Has anyone tackled this kind of issue? Is there something obvious I am missing?

    My Ditto Call:
    [!Ditto?parents=`[*id*]`&display=`all`&tpl=`ArticleDitto`!]

    My ditto template:
    <div class="ditto_item" id="ditto_item_[+id+]">
    <h3 class="ditto_pageTitle"><a href="[~[+id+]~]">[+pagetitle+]</a></h3>
    <div class="ditto_documentInfo">by <strong>[[GetAuthor]][+meta-author+]</strong> on [+date+]</div>
    <div class="ditto_introText">[+introtext+]</div>
    </div>

    Other attempts in the template:
    <div class="ditto_item" id="ditto_item_[+id+]">
    <h3 class="ditto_pageTitle"><a href="[~[+id+]~]">[+pagetitle+]</a></h3>
    <div class="ditto_documentInfo">by <strong>`[!GetAuthor!]`[+meta-author+]</strong> on [+date+]</div>
    <div class="ditto_introText">[+introtext+]</div>
    </div>

    <div class="ditto_item" id="ditto_item_[+id+]">
    <h3 class="ditto_pageTitle"><a href="[~[+id+]~]">[+pagetitle+]</a></h3>
    <div class="ditto_documentInfo">by <strong>`[!GetAuthor!][+meta-author+]`</strong> on [+date+]</div>
    <div class="ditto_introText">[+introtext+]</div>
    </div>

    <div class="ditto_item" id="ditto_item_[+id+]">
    <h3 class="ditto_pageTitle"><a href="[~[+id+]~]">[+pagetitle+]</a></h3>
    <div class="ditto_documentInfo">by <strong>[!GetAuthor!][+meta-author+]</strong> on [+date+]</div>
    <div class="ditto_introText">[+introtext+]</div>
    </div>

    Any help greatly appreciated.

    P
      • 10449
      • 956 Posts
      What does the GetAuthor snippet look like? The easiest way is to just define an author TV and use that TV-name in the Ditto-tpl. No additional snippet is then needed to fetch this value.
        • 23217
        • 44 Posts
        Thanks for responding.

        My GetAuthor looks like:
        <?php
        $pageMeta = $modx->getMETATags($modx->documentIdentifier);
        $authorName = "Toghers";
        foreach($pageMeta as $outerMeta)
        {
        if ($outerMeta["tag"] == "author")
        {
        $authorName = $outerMeta["tagvalue"];
        break;
        }
        }

        $modx->setPlaceholder("meta-author",$authorName);
        ?>

        I have also tried returning the $authorName rather than setting the placeholder.
          • 23217
          • 44 Posts
          I found a solution for this.

          I have a snippet GetAuthor:
          <?php
          $pageMeta = $modx->getMETATags($articleId);
          $authorName = "Toghers";
          foreach($pageMeta as $outerMeta)
          {
          if ($outerMeta["tag"] == "author")
          {
          $authorName = $outerMeta["tagvalue"];
          break;
          }
          }

          return $authorName;
          ?>

          I have a chunk for my Ditto template:
          <div class="ditto_item" id="ditto_item_[+id+]">
          <h3 class="ditto_pageTitle"><a href="[~[+id+]~]">[+pagetitle+]</a></h3>
          <div class="ditto_documentInfo">by <strong>[[GetAuthor?&articleId=`[+id+]`]]</strong> on [+date+]</div>
          <div class="ditto_introText">[+introtext+]</div>
          </div>

          and I have a Ditto call:
          [!Ditto?parents=`33`&filter=`template,21,1` &depth=`10`&tpl=`ArticleDitto`!]

          where parents=`33` and template 21 are specific to my site. It does a fine job of rendering an author if there is one, and a default (Toghers) if there is not